我想知道如何通过消息ID获得消息。香港专业教育学院尝试discord.fetch_message(id)和discord.get_message(id),都提出:Command raised an exception: AttributeError: module 'discord' has no attribute 'fetch_message'/'Get_essage'
[获得消息时,您将需要一个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
参考:
abc.Messageable
abc.Messageable
TextChannel.history()
TextChannel.history()