TypeError: Client.change_presence() missing 1 required positional argument: 'self'

vixitu

I am trying to make my bot change status every hour but it gives me the error in the title, I tried putting self but it would give me this error: AttributeError: 'statusscript' object has no attribute 'ws'.

    global list
    list = ["1", "2", "3"]

    @commands.command(aliases=['add'])
    async def addstatus(self, ctx, *, arg):
        global list

        list.append(arg)
        await ctx.send(f'`{arg}` added to status list')

    @commands.command()
    async def startstatus(self, ctx):
        @tasks.loop(seconds=3600)
        async def looper(self):
            duration = 3600
            print(f"LOOPER IS RUNNING EVERY {duration} SECONDS!")
            selected = random.choice(list)
            activity = selected
            client = commands.Bot
            await client.change_presence(activity=discord.Game(activity))
        looper.start(self)
RiveN
  1. Don't use variable names that are built-in data types. It sometimes doesn't work well, so it's a good practice to avoid it.
  2. I'm guessing this is a Cog because of self. Then when you want to refer to client you have to use self.client.

I created Test cog to let you see how it should look like:

class Test(commands.Cog):
    def __init__(self, client):
        self.client = client

    global status_list
    status_list = ["1", "2", "3"]

    @commands.command(aliases=['add'])
    async def addstatus(self, ctx, *, arg):
        global status_list

        status_list.append(arg)
        await ctx.send(f'`{arg}` added to status list')

    @commands.command()
    async def startstatus(self, ctx):
        self.looper.start()

    @tasks.loop(seconds=3600) # you can also use "hours=1" instead of seconds
    async def looper(self):
        duration = 3600
        print(f"LOOPER IS RUNNING EVERY {duration} SECONDS!")
        activity = random.choice(status_list)
        await self.client.change_presence(activity=discord.Game(activity)) # because you are in "Cog" you have to use self.client to refer to client

client.add_cog(Test(client))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TypeError: Missing 1 required positional argument: 'self'

How to Solve this " TypeError: read() missing 1 required positional argument: 'self' "

TypeError: gassens() missing 1 required positional argument: 'self'

TypeError: save() missing 1 required positional argument: 'self' : DjangoRestframework

TypeError at / save() missing 1 required positional argument: 'self'

TypeError: open_file() missing 1 required positional argument: 'self'

TypeError: get_params() missing 1 required positional argument: 'self'

TypeError: Function() missing 1 required positional argument: 'self'

TypeError: save() missing 1 required positional argument: 'self'

TypeError: GetSize() missing 1 required positional argument: 'self'

TypeError: endturn() missing 1 required positional argument: 'self'

Python - TypeError: listen() missing 1 required positional argument: 'self'

TypeError : kollision() missing 1 required positional argument: 'self'

TypeError: close() missing 1 required positional argument: 'self'

TypeError: player_attack() missing 1 required positional argument: 'self'

TypeError: str() missing 1 required positional argument: 'self'

TypeError: grid_configure() missing 1 required positional argument: 'self'

TypeError: main() missing 1 required positional argument: 'self'

TypeError: check() missing 1 required positional argument: 'self'

Getting TypeError fit() missing 1 required positional argument: 'self'

TypeError at /listing: save() missing 1 required positional argument: 'self'

TypeError: draw_shape() missing 1 required positional argument: 'self'

TypeError: GoogleAuth.LocalWebserverAuth() missing 1 required positional argument: 'self'

Missing 1 required positional argument: 'self' missing

save() missing 1 required positional argument 'self'

python: missing 1 required positional argument: 'self'

fit() missing 1 required positional argument: 'self'

main() missing 1 required positional argument: 'self'

missing 1 required positional argument: 'self' in class