0

I want to change the presence when a user executes a command. I have the Discord bot in an own Class. To change the presence I need the self argument. But when I write

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

I get the Error:

discord.ext.commands.errors.MissingRequiredArgument: ctx is a required argument that is missing.

And when I write:

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

I get this error:

discord.ext.commands.errors.MissingRequiredArgument: self is a required argument that is missing.

The whole code is:

    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()

Does anyone have a solution?

Axisnix
  • 2,822
  • 5
  • 19
  • 41
Jonathan
  • 76
  • 7

1 Answers1

0

Why do you put it in a class? It works fine when you leave it like the examples. If it's about running 2 bots in the same script then using this question will help you.

@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')

If you need to use multiple files, have a look at cogs.

Axisnix
  • 2,822
  • 5
  • 19
  • 41