I
I
Ivan Wagner2020-07-25 10:28:38
Python
Ivan Wagner, 2020-07-25 10:28:38

How can a discord bot view the presence of a role for a player, and not its existence on the server?

Hello! The question is. The bot listens to the !start command, and if the user does not have the BUNKER role, he will not be able to use it and vice versa if the role exists. But it happens that the role simply exists on the server, the user does not have it and he can write !start, and if the role is deleted from the server, it says that the role is needed.

@bot.command(name='start', help='Начать набор в игру.') #разрешаем передавать 
агрументы
async def start(context): #создаем асинхронную фунцию бота
creator = context.author

isCreatorCan = [ True if r.name == 'BUNKER' else False for r in 
creator.guild.roles]
if not any(isCreatorCan):
    message = await context.send("Только пользователь с ролью BUNKER может 
создавать игры.")
    return

room[creator.id] = creator

response = build_register_message()
message = await context.send(response)

await message.add_reaction("☢️")
await context.message.delete()

Help for God's sake, otherwise I'm afraid to throw this bot out the window

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Megum1n, 2020-07-25
@manavar_g

I'm using the Discord.py library .
There 's a role.members method that returns a list of all members of the role.

server = self.get_guild(server_id)
member = server.get_member(user_id)
role = server.get_role(role_id)

return True if member in role.members else False

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question