Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么可以';我不能用Discord.py禁止/踢某人吗?_Python_Discord.py - Fatal编程技术网

Python 为什么可以';我不能用Discord.py禁止/踢某人吗?

Python 为什么可以';我不能用Discord.py禁止/踢某人吗?,python,discord.py,Python,Discord.py,这是我的第一个代码 # IMPORT import discord from discord.ext import commands import os # INIT client = commands.Bot(command_prefix = '.') @client.command() async def load(ctx, extension): client.load_extension(f'cogs.{extension}') @client.command() as

这是我的第一个代码

# IMPORT

import discord
from discord.ext import commands
import os

# INIT

client = commands.Bot(command_prefix = '.')

@client.command()
async def load(ctx, extension):
    client.load_extension(f'cogs.{extension}')

@client.command()
async def unload(ctx, extension):
    client.unload_extension(f'cogs.{extension}')

@client.command()
async def reload(ctx, extension):
    client.unload_extension(f'cogs.{extension}')
    client.load_extension(f'cogs.{extension}')

for filename in os.listdir('./cogs'):
    if filename.endswith('.py'):
        client.load_extension(f'cogs.{filename[:-3]}')

        
client.run('My Token)
这是我的第二个密码

# IMPORT

import discord
from discord.ext import commands

# INIT

class Admin(commands.Cog):

    def __init__(self, client):
        self.client = client

    @commands.Cog.listener()
    async def on_member_join(self, member):
        print(f'{member} has joined a server')

    @commands.Cog.listener()
    async def on_member_remove(self, member):
        print(f'{member} has left a server')

    @commands.command(aliases=['cls'])
    @commands.has_permissions(kick_members=True)
    async def clear(self, ctx, amount=20):
        await ctx.channel.purge(limit=amount)
        await ctx.send("Refreshing channel")   

    @commands.command()
    @commands.has_permissions(kick_members=True)
    async def kick(self, ctx, member : discord.Member, *, reason=None):
        await member.kick(reason=reason)
        await ctx.send(f'Banned {member.mention}')

    @commands.command()
    @commands.has_permissions()
    async def ban(self, ctx, member : discord.Member, *, reason=None):
        await member.ban(reason=reason)
        await ctx.send(f'Banned {member.mention}')

def setup(client):
    client.add_cog(Admin(client))
因此,我已经运行了第一个代码,然后我尝试使用我的一个alt帐户进行测试,但是 不知何故,代码不起作用

我试着运行.ban,但它没有做任何事情,我也已经检查了控制台/cmd,但我没有看到任何错误

Python版本:3.8.3,
Discord.py 1.4.1

ctx
位于
self
之后,在代码中,在
成员
参数之后传递
ctx

@commands.command()
@commands.has_permissions(ban_members=True)
async def ban(self, ctx, member: discord.Member, *, reason=None):
    await member.ban(reason=reason)
    await ctx.send(f'Banned {member.mention}')
你在这一行也有一个打字错误:

await onmember.kick(reason=reason) #  Should just be member.kick

所以我已经按照你说的做了,但是仍然不起作用,我用alt再次测试了它,但是没有发生任何事情,控制台/cmd中仍然没有信息或错误消息。你需要将权限传递给
has_permissions
,即:
@commands.has_permissions(ban_members=True)
我已经尝试了ban_members=True,但它似乎仍然不起作用,这也适用于kick,而且服务器是我自己的,所以它为什么不起作用仍然很奇怪。。。