微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Discord.py: MissingRequiredArgument: self 是缺少的必需参数

如何解决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()

有人有解决办法吗?

解决方法

你为什么把它放在一个类中?当您像示例一样离开它时,它工作正常。如果要在同一个脚本中运行 2 个机器人,那么使用此 question 会对您有所帮助。

@bot.event
async def on_ready():
    print("My Ready is Body")

@bot.command()
async def change(ctx):
    await self.client.change_presence(activity=discord.Game("P-Hub"))

bot.run('token')

如果您需要使用多个文件,请查看cogs

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?