如何通过 id discord.py 获取消息 [英] How to get message by id discord.py

查看:34
本文介绍了如何通过 id discord.py 获取消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm wondering how to get a message by its message id. I have tried discord.fetch_message(id) and discord.get_message(id), but both raise:

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

推荐答案

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

When getting a message, you're going to need an abc.Messageable object - essentially an object where you can send a message in, for example a text channel, a DM etc.

@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


参考资料:

这篇关于如何通过 id discord.py 获取消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆