How To Assign A User A Role In A Server From A Direct Message Discord.py
So I am trying to make a bot where if a user direct messages the bot, it will give them a role in a server that both the user and the bot are in. I tried to just add the role based
Solution 1:
Here we record the ids and then access the appropriate objects when we recieve the command.
target_server_id = "123..."
target_role_id = "456..."
@bot.command(pass_context=True)
async def gimmieRole(ctx):
if not ctx.message.channel.is_private:
await bot.say("Private command only")
server = await bot.get_Server(target_server_id)
role = discord.utils.get(server.roles, id=target_role_id)
member = server.get_member(ctx.message.author.id)
if member:
await bot.add_roles(member, role)
else:
await bot.say("You are not a member")
Post a Comment for "How To Assign A User A Role In A Server From A Direct Message Discord.py"