python - 由于某种原因我的禁令命令不起作用,我不知道如何修复它(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'
我需要我能得到的所有帮助。提前致谢!
解决方案
您正在执行 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
使用
推荐阅读
- performance - Jmeter :- 在并发线程中按顺序运行一组采样器
- python - 如何将时间数据转换为数值?
- angular - 在一个 ts 文件中使用多个加载器服务
- javascript - 使用 javascript(无意)打开移动应用程序(如果已安装)
- python - 创建一个填写标准 Python + Django 代码中的字段的表单
- jquery - 检查代码是否符合 jquery 3.x 的简单方法?
- javascript - 如何在响应式视频元素上居中播放按钮
- coldfusion - 如何定位和替换值
- laravel - 从 Laravel 中的日期列查询两个日期之间的数据
- javascript - Jquery滚动功能在iphone设备上不起作用