Hon*_*oop 5 python message url-rewriting 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'
Run Code Online (Sandbox Code Playgroud)
Dig*_*gy. 11
收到消息时,您将需要一个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
Run Code Online (Sandbox Code Playgroud)
参考:
| 归档时间: |
|
| 查看次数: |
25033 次 |
| 最近记录: |