When I do my discord.py project, I found out that the following codes work well in the first time but return an attribute error for the second time (in a single run).
class Test2(commands.Cog):
def __init__(self, dc_bot):
self.bot = dc_bot
self.ui = ""
@commands.command(description="get avatar")
async def getavatar(self, ctx, *, content: str):
avatar = self.bot.user.avatar_url
self.ui += content
await ctx.send(content)
await ctx.send(avatar)
self.__init__(self) # reset the values
First time it works well.
Second time it will say: AttributeError: 'Test2' has no attribute 'user'
I guess because I want to reset self.ui for the next run.
And if there are a lot of "self" in my init function that I need to use, I thought (before) that it is a good idea to just called the init function. But running again self.ui = dc_bot
will cause this problem I think. Could you explain why this would happen please?