首页 > 解决方案 > 由于某种原因我的禁令命令不起作用,我不知道如何修复它(discord.py)

问题描述

大约一个月前,我为我的机器人发出了禁令命令,几天前,它刚刚停止工作。有谁知道为什么?这是我的代码:

@client.command()
@commands.has_permissions(ban_members=True)
async def ban(ctx, member : discord.Member, *, reason=None):
    await member.ban(reason=reason)

这是我得到的错误:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Context' object has no attribute 'ban'

我需要我能得到的所有帮助。提前致谢!

标签: pythondiscord.py

解决方案


您正在执行 Cog 中的命令。类(在本例中为 Cog)中的所有方法(函数)都有它们的第一个集合,self即类本身。

因为你没有传递 "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)

此外,考虑到commands.has_permissions仅适用于当前频道,您可能希望commands.has_guild_permissions使用


推荐阅读