Reputation: 11
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
Reputation: 6944
A couple of things to mention:
prisoner
, and if that's the case, then you made a typo; prisioner
.await
ing a few things unnecessarily. The await
keyword should only be used for coroutines (it'll tell you in the docs).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.
@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:
Member.move_to()
Guild.get_role()
Guild.get_channel()
VoiceState.channel
commands.Context
discord.on_message
Bot.process_commands()
Upvotes: 3