【问题标题】:How does my discord bot find a message by message.id? (previously posted by the bot)我的不和谐机器人如何通过 message.id 找到消息? (之前由机器人发布)
【发布时间】:2019-08-15 05:16:03
【问题描述】:

我需要找到该机器人之前发布的消息,然后查看其上的反应。我认为我没有正确使用:discord.utils.find()

我环顾四周,但找不到任何关于 Discord.py 的东西,我能找到的所有东西都是关于 Discord.js 的。

这是我的代码:

import discord

TOKEN = '[I have a token here]'

client = discord.Client()

m_id = 0

@client.event
async def on_message(message):

    if message.author == client.user:
        global m_id
        m_id = message.id

    if not message.author == client.user:
        if message.content.startswith('!poll'):
            msg = 'Test poll \nMessage ID: {0.id}'.format(message)
            await client.send_message(message.channel, msg)

        if message.content.startswith('!endpoll'):
            new_message = discord.utils.find(lambda m: m.id(m_id), client.messages)
            print(new_message.reactions)

@client.event
async def on_ready():
    print('Logged in as')
    print(client.user.name)
    print(client.user.id)
    print('------')

client.run(TOKEN)

我需要我的机器人打印一份对其初始消息的反应列表。

【问题讨论】:

    标签: python-3.x discord.py


    【解决方案1】:

    这里有两种通过 id 查找消息的方法。我希望这就是你的意思

    
    @bot.event
    async def on_message(msg):
        if 'conditoin' == True:
            message=await bot.get_message(msg.channel,'message_id')
            print(message.content)
    
    @bot.command(pass_context=True)
    async def get_msg(con,msg_id:int):
        message=await bot.get_message(con.message.channel,msg_id)
        print(message.content)
    
    

    【讨论】:

      猜你喜欢
      • 2018-11-19
      • 1970-01-01
      • 2021-08-14
      • 2021-05-29
      • 2022-11-02
      • 2020-04-21
      • 1970-01-01
      • 2020-12-06
      • 1970-01-01
      相关资源
      最近更新 更多