The goal I had in mind was that my discord bot changes it's status after some time to a random status I added to a list.
import discord
import random
from discord.ext import commands, tasks
class Status(commands.Cog):
def __init__(self, client):
self.client = client
self.client.random_status_loop.start()
@tasks.loop(seconds=5.0)
async def random_status_loop(self):
status = [
'Value1',
'Value2',
'Value3',
'Value4',
'Value5',
'',
'Value6']
await self.client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=(random.choice(status))))
def setup(client):
client.add_cog(Status(client))
I've just been following some tutorials on this and am still new to programming with Python. This is what I put inside a cog, within the main bot.py file this works fine but when putting it in a cog it gives me the following error:
discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.status' raised an error: AttributeError: 'Bot' object has no attribute 'random_status_loop'
Is there something I might be missing, do I have to add a specific attribute for it to work?
Any help is appreciated.
question from:
https://stackoverflow.com/questions/65540673/how-can-i-create-a-random-status-changer-within-a-cog 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…