I'm wondering how to get a message by its message id. I have tried discord.fetch_message(id)
and discord.get_message(id)
, but both raise:
Command raised an exception: AttributeError: module 'discord' has no attribute 'fetch_message'/'get_message'
Add a search option in the search bar with the name: "ID". This feature would allow user's who cannot code bots, or don't have bots that can fetch messages to find specific messages with IDs. If no message is found an error can be returned, etc.
They've decided to step down from the role of maintainer and it marks a sad end to the entire community. The API allowed us, the python-developers to quickly create bots with modern features like Asynchronous Python.
person.speak () person.walk () person.left_hand.grab (a_thing) In discord py, decorators curate special objects for you. If you use on_message, you get a message object, if you use commands you get a context object. What you want to go read in the docs is what are the attributes and methods of the objects you get in the different functions.
To check who send the message, you would do message.author to get a Member object which has attributes such as display_name which is a string that prints out what their nickname is or mention which is a string that has what you need to mention that user Where can i find discord.py2..
If the message has not been sent it doesn't exist yet so there will not be an ID. If you want to edit the message after it has been sent the send function returns a Message object that is the sent message. I can't give you a running example right now but the pseudo-code would look like this.
When getting a message, you're going to need an abc.Messageable
object - essentially an object where you can send a message in, for example a text channel, a DM etc.
@bot.command()
async def getmsg(ctx, msgID: int): # yes, you can do msg: discord.Message
# but for the purposes of this, i'm using an int
msg = await ctx.fetch_message(msgID) # you now have the message object from the id
# ctx.fetch_message gets it from the channel
# the command was executed in
###################################################
@bot.command()
async def getmsg(ctx, channel: discord.TextChannel, member: discord.Member):
msg = discord.utils.get(await channel.history(limit=100).flatten(), author=member)
# this gets the most recent message from a specified member in the past 100 messages
# in a certain text channel - just an idea of how to use its versatility
References:
abc.Messageable
TextChannel.history()
TextChannel.fetch_message()
Context.fetch_message()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With