discord py message content code example

Example 1: on message discord py

@bot.event
async def on_message(message):
    if message.content == "pong":
        await message.channel.send('ping')

Example 2: discord py message link

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

Example 3: discord.py get message text

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.

Example:
@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

Tags:

Misc Example