如何通过 id discord.py 获取消息

How to get message by id discord.py

我想知道如何通过消息 ID 获取消息。我试过 discord.fetch_message(id)discord.get_message(id),但都加注:

Command raised an exception: AttributeError: module 'discord' has no attribute 'fetch_message'/'get_message'

收到消息时,您将需要一个 abc.Messageable 对象 - 本质上是一个您可以在其中发送消息的对象,例如文本通道、DM 等。

示例:

@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

参考文献: