python-3.x - Discord.py:MissingRequiredArgument:self 是缺少的必需参数
问题描述
我想在用户执行命令时更改存在。我在自己的班级中有 Discord 机器人。要改变存在,我需要 self 参数。但是当我写
@bot.command()
async def change(self, ctx):
await self.client.change_presence(activity=discord.Game("P-Hub"))
我得到错误:
discord.ext.commands.errors.MissingRequiredArgument: ctx is a required argument that is missing.
当我写:
@bot.command()
async def change(ctx, self):
await self.client.change_presence(activity=discord.Game("P-Hub"))
我收到此错误:
discord.ext.commands.errors.MissingRequiredArgument: self is a required argument that is missing.
整个代码是:
class DiscordBot():
def __init__(self, client, token):
self.client = client
self.token = token
def run(self):
self.client.run(self.token)
@bot.command()
async def change(ctx, self):
await self.client.change_presence(activity=discord.Game("P-Hub"))
@bot.event
async def on_ready():
print("My Ready is Body")
@bot.listen()
async def on_message(message):
print(str(message.author) + ": " + message.content)
if __name__ == '__main__':
client = DiscordBot(bot, 'token')
client.run()
有没有人有办法解决吗?
解决方案
推荐阅读
- java - CompressBackupUtil 不备份 blob
- c++ - 左移对指针变量有什么作用?
- android - 进程 'command '/home/ns1/Android/Sdk/build-tools/23.0.3/aidl'' 以非零退出值 1 结束
- assembly - RISCV中如何表示乘法指令的乘积?
- azure - 提醒我如何将 HTTP 数据拆分为并行分支并在逻辑应用程序中执行进一步的步骤?
- regex - 正则表达式只允许数字、带点的数字、& 和空格
- python - 在 Django 中连续运行后台任务
- google-ads-api - 如何从 Google Adwords API 中提取基于不同归因模型的转化结果
- javascript - 为什么 JavaScript/jQuery 过滤列表在 iPhone 中不起作用?
- android - Android Swipe手势和项目点击都不能在RecyclerView中一起工作