Discord.py Reaction bot that gives a role

Deadly 提交于 2019-12-10 11:02:15

问题


How do I make a bot that would give people roles when they reacted to a specific thing? So far I have this but it does not work

@client.event
async def on_ready():
    channel = client.get_channel('513546504481406979')
    role = discord.utils.get(user.server.roles, name="testrole")
    message = await bot.send_message(channel, "React to me!")
    while True:
        reaction = await bot.wait_for_reaction(emoji="👍", message=message)
        await bot.add_roles(reaction.message.author, role)

回答1:


wait_for_reaction returns a (reaction, user) tuple. You only need the user portion to assign the role:

reaction, reactor = await bot.wait_for_reaction(emoji="👍", message=message)
await bot.add_roles(reactor, role)


来源:https://stackoverflow.com/questions/53357677/discord-py-reaction-bot-that-gives-a-role

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!