Answer the question
In order to leave comments, you need to log in
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()
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question