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

问题描述 投票:1回答:1

我想知道如何通过消息ID获得消息。香港专业教育学院尝试discord.fetch_message(id)和discord.get_message(id),都提出:Command raised an exception: AttributeError: module 'discord' has no attribute 'fetch_message'/'Get_essage'

python url-rewriting message discord.py id
1个回答
1
投票

[获得消息时,您将需要一个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

参考:

© www.soinside.com 2019 - 2024. All rights reserved.