B
B
Bot-Developer2021-10-01 20:15:25
Python
Bot-Developer, 2021-10-01 20:15:25

How to replace client in cogs?

I tried to make the command unbanned, but it gives an error:

Command raised an exception: NameError: name 'client' is not defined

I don't know how to replace "client" to make it work. Code I am using:
@commands.command(
    aliases = ["разбан"],
    name = "unban",
    brief = "Разбанить пользователя",
    usage = "unban <user>"
  )
  async def unban(ctx, id: int):
    user = await client.fetch_user(id)
    await ctx.guild.unban(user)

(I use kogi)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
Bot-Developer, 2021-10-02
@Bot-Developer

Solved the problem. The code I used:

@commands.command(
    aliases = ["разбан"],
    name = "unban",
    brief = "Разбанить пользователя",
    usage = "unban <user>"
  )
  async def unban(self, ctx, id: int):
    user = await self.client.fetch_user(user_id=id)
    await ctx.guild.unban(user)

V
Vindicar, 2021-10-01
@Vindicar

You can write the id type not int, but discord.Member, if I'm not confused. Then fetch_user() won't be needed either.
PS: But the unban command is rather useless, it's faster to do it through the discord interface. =p

T
TanderOFF, 2021-10-02
@TanderOFF

just add self to get self.client.fetch_user(id)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question