У меня проблема с добавлением роли, когда пользователь реагирует на сообщение.
Как я хочу, чтобы это работало, так это то, что когда пользователь присоединяется к серверу Discord, бот отправит отправить сообщениеиспользуя событие on_join
(сейчас я использую команду test
для тестирования).
Следующим шагом является событие on_reaction_add
, когда пользователь реагирует на это сообщение, бот добавляет роль этому пользователю.
Вот с чем я работаю.Я проверил это, однако, я не получаю желаемый результат.
(перезаписать на discord.py)
@commands.command(pass_context=True)
async def test(self, user: discord.Member): #lets change this to the command 'test' for now and change on on_join event later.
guildName = user.guild.name
embed = discord.Embed(colour=discord.Color(random.randint(0x000000, 0xFFFFFF)))
embed.title = "Welcome to {} {}!".format(guildName, user)
embed.description = "Head over to <#443133907102203912> to have a read up on our rules. Once you have read them please reaction to this post with a :thumbsup:"
embed.set_image(url='')
await user.send(embed=embed)
async def on_reaction_add(reaction, user):
channelid = '555844758778544160' #The text-channel where the react should happen
role = discord.utils.get(user.guild.roles, name="Members") #The role applied when the post is reacted to
if reaction.message.channel.id != channelid:
return #So it only happens in the specified channel
if str(reaction.emoji) == "<:thumbsup:555844758778544160>":#The reaction (not sure if this should be raw in discord.py rewrite)
await user.add_roles(user, role)#Adds role when post is reacted to