如何检查另一台服务器上的用户角色?

时间:2019-03-30 01:10:09

标签: discord.py

有一个检查特定服务器上角色的函数,但是该函数应该由pm发送给机器人,所以我不能在[role.id]中使用“角色代码”来表示message.author中的角色.roles] 我该怎么办?

还需要向特定服务器发送消息

有关功能:

async def on_message(message):
    if '%attented' in message.content:
        if "561055432748302336" in [role.id for role in message.author.roles]:
            msg = message.content.split(' ')
            author = message.author
            await client.send_message(client.get_channel('560679934209687552'), str(author) + ' has attented a ' + msg[2] + '\nScreenshot:' + msg[1] + '/n***To approve screenshot react with :HYPERS: to dissaprove react with :FeelsBadMan:***')

1 个答案:

答案 0 :(得分:0)

您可以为此使用两种方法

@bot.event
async def on_message(msg):
    for i in bot.servers:
        for x in i.roles:
            if x.id == 'the role id': #this can also be done through name via x.name == 'name'
                await bot.send_message(discord.Object(id='channel id'), 'the message')
    await bot.process_commands(msg)

@bot.command(pass_context=True)
async def role(msg):
    for i in bot.servers:
        for x in i.roles:
            if x.id == ' the role id': #you can also do this by name via x.name
                await bot.send_message(discord.Object(id='channel id here'), "The message to send")

@bot.event
async def on_reaction_add(emote,user):
    if emote.emoji == '':
        #Do something here
        await bot.send_message(emote.message.channel,f"{user.name} has reacted")

@bot.command(pass_context=True)
async def get_message(msg):
    async for i in bot.logs_from(msg.message.channel):
        if i.author.id == '185181025104560128' and 'hello' in i.content:
            print(i.content)

您无法通过async中的常规命令功能来获得对消息做出反应的用户,而只能在rewrite中进行操作,但是可以使用on_reaction_add事件来完成操作asyncrewrite中的功能