0

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?

1 Answer 1

3

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:

Sign up to request clarification or add additional context in comments.

3 Comments

hey thanks alot for helping, but i tested the code u sent and it's still not working, btw those numbers are both role and voice channel IDs, respectively. if it helps im using the latest version of discord.py, if im not wrong. And the code i showed first sent might have some similarities with a older discord.py because i watched some videos that might be also old. But again thanks alot for helping
Nvm i found the error, in your code there's a "ctx" missing, but besides that it is working just how i needed it to work :), again and beeing a little repetitive, thanks alooot
Good spot, sorry I should've proof-read it a couple more times before sending it! Glad you got it working :) Also, go ahead and accept the answer if it helped you, as it'll make it easier for others with the same issue to find a solution! Good luck with the bot :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.