0
votes

I wouuld like to give a user who private messages the bot a specific role in a specific server. How can I do this, I can not find anything in the internet. Code I have right now (doesnt work and is outdated):

        target_server_id = "623597980175433749"
        target_role_id   = "656158110179655701"


        #if not ctx.message.channel.is_private:
            #await client.say("Private command only")
        server = await client.get_guild(target_server_id)
        role = discord.utils.get(guild.roles, id=target_role_id)
        member = guild.get_member(ctx.message.author.id)
        if member:
            await client.add_roles(member, role)
        else:
            await client.say("You are not a member")
1

1 Answers

1
votes

I think the only changes you need to make are to use integers for the ids, change client.add_roles to member.add_roles, and use ctx.send

target_server_id = 623597980175433749
target_role_id   = 656158110179655701

if not ctx.guild is not None:
    await ctx.send("Private command only")
server = await client.get_guild(target_server_id)
role = discord.utils.get(guild.roles, id=target_role_id)
member = guild.get_member(ctx.message.author.id)
if member:
    await member.add_roles(role)
else:
    await ctx.send("You are not a member")