如何使用Discord.py创建基于反应的角色分配系统?

时间:2018-07-03 01:32:30

标签: python bots discord discord.py

我一直在尝试创建一个设置,在该设置中,文本通道中存在一条永久性消息,用户可以对其进行响应以接收特定角色。据我所知,我遇到了一种实现此目的的方法,但是我缺少使它能够正常工作的东西。这是我到目前为止的内容:

import discord
from discord.ext.commands import Bot
from discord.ext import commands
from discord.utils import get

bot_prefix = "r!"
bot = commands.Bot(command_prefix=bot_prefix)

@bot.event
async def on_ready():
    print("Bot Online!")
    print("Name: {}".format(bot.user.name))
    print("ID: {}".format(bot.user.id))
    await bot.change_presence(game=discord.Game(name='Visit the roles channel!'))

class Main_Commands():
    def __init__(self, bot):
    self.bot = bot

# r!ping
@bot.command(pass_context=True)
async def ping(ctx):
    await bot.say("Pong!")

@bot.event
async def on_reaction_add(reaction, user):
    role = discord.utils.get(WHAT GOES HERE, name="463359356281421844")
    roleChannelId = "463374724702142464"
    if reaction.message.channel.id != roleChannelId:
        return
    if str(reaction.emoji) == u"\U0001F534":
        await bot.add_roles(user, role)

bot.run("TOKEN")

我似乎无法弄清楚我需要列出什么才能迭代。我知道它需要从服务器获取角色,我只是不知道该怎么做。此外,我已经了解到on_reaction_add实际上仅在启动机器人后 发送消息时才有效,这出于很多原因都不好。您可以遍历我正在寻找的路线吗,有办法避免on_reaction_add的陷阱吗?

0 个答案:

没有答案