1

I have tried looping in my bot. The loop is suppose to update the member counter. I wanted double check to see if this is correct as it doesn't update the stats. The channel itself can be made trough the command its the part of updating that I am having trouble with any help is greatly appreciated. There is no error showing and I am really confused. Thank you in advance!

import nextcord
from nextcord.ext import commands, tasks
from nextcord.webhook import async_

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


    @tasks.loop(minutes=1)
    async def looped_task(self,):
        text_channel_list = []
        stats = len(self.guild.members)
        channel = self.client.get_channel.startswith('Members: ')
        for guild in self.client.guilds:
            for channel in guild.text_channels:
                text_channel_list.append(channel)
                if channel == True:
                    await channel.edit(channel, name = f"Members: {stats}")
    
    
    @commands.command()
    async def stat(self, ctx):
        channel = self.client.get_channel.startswith('Members')
        stats = len(ctx.guild.members)
        await ctx.guild.create_voice_channel(name=f"Members:{stats}", category=None)
        await ctx.send(f"Your Server has {stats} members")
                
def setup(client):
    client.add_cog(stats(client))

1 Answers1

0

Did you start your task? If not, it won't update it of course. When using tasks that loop, they need to be started as described in the documentation. Specifically the task.start()

You could add in this piece of code in your Cog to start it when the Cog itself is ready.

@commands.Cog.listener()
async def on_ready(self):
    self.looped_task.start()
DrummerMann
  • 692
  • 4
  • 9