[英]How do I get the message content of a channel in discord.py
这是我的代码,但它返回的是消息 ID 而不是消息内容
@bot.command(name="jpg")
async def jpg_File(message):
channel = bot.get_channel(699577970117050399)
messages = await channel.history(limit=500).flatten()
print(messages)
这是我从打印消息中得到的: <Message id=937077040878866442 channel=<TextChannel id=699577970117050399 name='memes' position=2 nsfw=False news=False category_id=699624938583359608
您需要访问message
object 的content
属性。
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.