Def4ltt
Def4ltt

Reputation: 11

Discord bot command not working (Discord.py)

I've been trying to create a discord bot with Python. One of the commands was suppose to remove of the user's roles and add a specific one. And then if they were on a voice channel send them to another specific voice channel. I tried the following code:

@client.command()
async def prisioner(member:discord.member):
    role=await guild.get_role(702269742014005248)
    channel=await guild.get_channel(690488036781195294)
    await client.add_roles(member, role)
    if member.activity!=None:
        await move_to(channel)

It's not working and doesn't show any errors on the IDLE. Can someone help?

Upvotes: 1

Views: 5333

Answers (1)

Diggy.
Diggy.

Reputation: 6944

A couple of things to mention:

  • When using command decorators, Context is always the first argument (see references).
  • Be careful with your spelling, as I'm guessing the command was supposed to be called prisoner, and if that's the case, then you made a typo; prisioner.
  • It seems that some of the code's syntax is based off of the old discord.py version, so when using documentation, stick to the most recent one (see references).
  • You seem to be awaiting a few things unnecessarily. The await keyword should only be used for coroutines (it'll tell you in the docs).
  • You're setting parameter types really well - definitely a good habit to get into from the get-go.

And before we move onto your command, please make sure you have await client.process_commands(message) if you're using an on_message(message) event.

Your command, rewritten:

@client.command()
async def prisoner(ctx, member: discord.Member):
    role = ctx.guild.get_role(702269742014005248)
    v_channel = ctx.guild.get_channel(690488036781195294) # assuming this is a voice channel?
    await member.add_roles(role)
    if member.voice.channel: # checks user is connected to a voice channel
        await member.move_to(v_channel)
        await ctx.send(f"Successfully imprisoned {member.mention}!")

References:

Upvotes: 3

Related Questions