M
M
Mind20772021-09-27 21:03:06
Python
Mind2077, 2021-09-27 21:03:06

How to issue a role on a specific server, knowing the server ID and user ID?

I am writing a bot with a verification system for my server. The bottom line is this: when entering the server, the bot writes a message to the user's PM, which indicates, for example, "write .verification" (simplified) in the bot's PM. After that, the bot will issue a role on the desired server (the bot will be used only on 1 server). I was able to implement everything except the issuance of a role. When messaging in PM, the bot records the user as a user, not as a member, which is why it cannot give a role. Can someone help?

@bot.command()
@commands.dm_only()
async def верификация(ctx, code):
    if code == '162933':
        member = ctx.message.author
        await member.add_roles(discord.utils.get(member.guild.roles, id=891743318852116490))
        await member.edit(nick='123')
        await member.send('Верификация прошла успешно!  Доступ к серверу открыт.')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-09-27
@Mind2077

Find a user on the server through get_member and assign the role
The server can be obtained in the same way through get_guild

guild = bot.get_guild(gid)
member = guild.get_member(ctx.message.author.id)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question