0
votes

I'm using cogs to shorten and organise my discord bot. However upon attempting a "Events" cog I'm faced with a NameError of changePlaying not being defined despite it literally being about the on_ready command

A: I forgot to import discord.ext and hence imported that. B: I've tried changing the location of the list of possible statuses in and out of the changePlaying event

PlayingList = [Maximus.py.","!help"]
async def changePlaying(self):
    while True:
        await self.bot.change_presence(game=Game(name=random.choice(PlayingList)))
        await asyncio.sleep(120)


async def on_ready(self):
    print('Logged in as')
    print(self.bot.user.name)
    print(self.bot.user.id)
    print('-----------------------------------------')
    print('Log in complete')
    for x in range(5):
        print("")
    self.bot.loop.create_task(changePlaying(self))

Well I think it's clear what the expected results are but to clarify the bot is supposed to boot. It does come online and does listen to commands but the status bar does not change

1

1 Answers

0
votes

In view of the self argument of the methods, I see they are in the cog. You should use PlayingList as an attribute of the cog, that is, in its __init__ add instead self.PlayingList = ["Maximus.py.","!help"] and then access it through self. in the methods.

And so the answer is : you aren't using methods correctly. You have to do self.changePlaying() not changePlaying(self).

By the way, use a tuple instead of a list if you do not plan to modify it through the execution. And a variable name shouldn't start with a capital letter, as it is commonly reserved to classes. See PEP 8.