简体   繁体   中英

How do I get the message content of a channel in discord.py

This is my code but it is returning the message id's instead of the message content

@bot.command(name="jpg")
async def jpg_File(message):
    channel = bot.get_channel(699577970117050399)
    messages = await channel.history(limit=500).flatten()
    print(messages)

This is what I get from printing messages: <Message id=937077040878866442 channel=<TextChannel id=699577970117050399 name='memes' position=2 nsfw=False news=False category_id=699624938583359608

You need to access the content attribute of the message object.

async def jpg_File(message):
    channel = bot.get_channel(699577970117050399)
    messages = await channel.history(limit=500).flatten()
    print(messages)
    for i in messages:
        print(i.content)
@client.event async def on_message(message: discord.Message): channel = discord.utils.get(message.guild.text_channels, name="general") messages = await channel.history(limit=500).flatten() for message in messages: if not message.attachments: print(message.author, message.content) else: print(message.author, message.attachments)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM