Warren Jennings
Warren Jennings

Reputation: 23

How does my discord bot find a message by message.id? (previously posted by the bot)

I need to find a message the bot has previously posted, then see the reactions on it. I don't think I'm using: discord.utils.find() correctly.

I've looked around but haven't been able to find anything for Discord.py, all the stuff I could find was for Discord.js.

Here's my code:

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)

I need my bot to print a list of reactions to it's initial message.

Upvotes: 1

Views: 2858

Answers (1)

KowaiiNeko
KowaiiNeko

Reputation: 327

Here are two methods for finding a message by id. I hope this is what you meant


@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)

Upvotes: 1

Related Questions