#what causes this error

1 messages · Page 1 of 1 (latest)

deft lance
#

I have only 2 on_ready events:

@bot.event
async def on_ready():
    print(f'Bot {bot.user} is ready to work!')

and

    @commands.Cog.listener()
    async def on_ready(self):
        self.unban_loop.start()
        self.last = 0
    
    
    @tasks.loop(hours=6)
    async def unban_loop(self):
        await self.bot.wait_until_ready()
        new = []

        ban_data_r = open('ban_data.txt', 'r')

        for data in ban_data_r:
            m, u, _, _, _ = data.split('\t')
            if datetime.strptime(u, '%Y-%m-%d %H:%M:%S.%f') < datetime.now():
                role = self.bot.get_guild(1395455130048004226).get_role(1396560189737668648)  # id сервера и роль бана
                await self.bot.get_guild(1395455130048004226).get_member(int(m)).remove_roles(role)
            else:
                new.append(data)

        ban_data_r.close()

        ban_data_w = open('ban_data.txt', 'w')
        ban_data_w.writelines(new)
        ban_data_w.close()

and how can I improve unbanning system?

#

for context data in 'ban_data.txt' looks like

f'{member.id}\t{until}\t{inter.author.id}\t{reason}\t{datetime.datetime.now()}\n'
desert forge
#

read the warning

#

you can start the task in the cog init

deft lance
# desert forge you can start the task in the cog init

thanks a lot
should be like this?

class UnbanLoop(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.unban_loop.start()
    
    
    @tasks.loop(hours=6)
    async def unban_loop(self):
        await self.bot.wait_until_ready()
        new = []

        ban_data_r = open('ban_data.txt', 'r')

        for data in ban_data_r:
            m, u, _, _, _ = data.split('\t')
            if datetime.strptime(u, '%Y-%m-%d %H:%M:%S.%f') < datetime.now():
                role = self.bot.get_guild(1395455130048004226).get_role(1396560189737668648)  # id сервера и роль бана
                await self.bot.get_guild(1395455130048004226).get_member(int(m)).remove_roles(role)
            else:
                new.append(data)

        ban_data_r.close()

        ban_data_w = open('ban_data.txt', 'w')
        ban_data_w.writelines(new)
        ban_data_w.close()


def setup(bot):
    bot.add_cog(UnbanLoop(bot))
desert forge
#

yeah it should be fine

#

try it

deft lance
#

thank you for help