I was wondering if there was a way to get the message from the message link (https://discordapp.com/channels/guild_id/channel_id/message_id) using a Python Discord bot, and if so, how to. I can think of a way using
link = 'https://discordapp.com/channels/guild_id/channel_id/message_id'.split('/')
message = await self.bot.get_guild(int(link[-3])).get_channel(int(link[-2])).fetch_message(int(link[-1]))
but I was wondering if there is a more direct way. Thanks in advance!
To do this you should first get the guild, channel and message ids by doing this:
server_id = int(link[4])
channel_id = int(link[6])
msg_id = int(link[5])
Next you should use the bot to get the guild object, then use the guild object to get the text channel object and then finally use the text channel object to get the message object. Like this:
server = client.get_guild(server_id)
channel = server.get_channel(channel_id)
message = await channel.fetch_message(msg_id)
discord.py get_guild() reference: https://discordpy.readthedocs.io/en/latest/api.html#discord.Client.get_guild
discord.py get_channel() reference: https://discordpy.readthedocs.io/en/latest/api.html#discord.Guild.get_channel
discord.py fetch_message() reference: https://discordpy.readthedocs.io/en/latest/api.html#discord.abc.Messageable.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