【问题标题】:How to get message by id discord.py如何通过 id discord.py 获取消息
【发布时间】:2020-05-17 11:39:49
【问题描述】:

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

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

【问题讨论】:

  • 请参阅:stackoverflow.com/a/49419190discordpy.readthedocs.io/en/rewrite/…。认为语法是channel.fetch_message(id)
  • 你能做 guild.fetch_message(id) 吗?
  • 好的,还有一个问题,你如何获得他们发送命令的当前频道?
  • 哦,好的,我看到你的下一个回复后发送了,对此感到抱歉
  • guild = ctx.guild channel = guild.channels message = await channel.fetch_message(int(id)) raises: 命令引发异常:AttributeError: 'list' object has no attribute 'fetch_message'

标签: python url-rewriting discord.py message


【解决方案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

参考资料:

【讨论】:

  • 很高兴听到这个消息!祝机器人好运:)
  • 感谢我一直在努力,这很有趣,我不知道,但我有一个完整的货币系统与 mongodb,lmao。
  • 哈哈,一切都来得及。很快,您甚至不需要任何文档,代码将从您的手指间流淌,就像没有明天一样!
  • 哈哈,是的,希望如此。你有不和吗?我是@ɦօռɛʏքօօք#0099,如果你想加我的话。
  • 发送好友请求!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-05-04
  • 2013-04-02
  • 2017-12-08
  • 2018-09-01
  • 2014-09-26
  • 1970-01-01
  • 2022-07-10
相关资源
最近更新 更多