2 回答

TA貢獻(xiàn)1869條經(jīng)驗(yàn) 獲得超4個(gè)贊
ctx.send()返回discord.Message它發(fā)送的消息的實(shí)例,因此您可以將其存儲(chǔ)在變量中。
message = await ctx.send(f"{ctx.message.author.mention}, Hi!")
# do what you want with the message, in your case getting it's id
bot_message_id = message.id
至于你的第二個(gè)問題,如果你想獲得用戶對(duì)該消息的響應(yīng)(因此特定用戶將發(fā)送的下一條消息),你可以使用內(nèi)置函數(shù)wait_for。
def check(message):
? ? return message.author.id == the_id_of_that_user
message = await bot.wait_for("message", check=check)
這樣,機(jī)器人實(shí)際上就會(huì)發(fā)出wait for
一條消息,使您的check
函數(shù)返回True
,或者在本例中是由該用戶發(fā)送的消息。

TA貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超4個(gè)贊
我不太明白你的問題,但我會(huì)盡力回答。根據(jù)API 參考,您可以使用 獲取某人的最后一條消息channel.history().get()
。這是一個(gè)例子:
import discord
from discord.ext import commands
async def anyfunc(ctx):
? ? await ctx.send(f"{ctx.message.author.mention}, Hi!")
? ? bot_message_id = await ctx.channel.history().get(author__name="Bot's name").id
這可能會(huì)起作用,但如果出現(xiàn)錯(cuò)誤,也許您可以嘗試author__id=bot's id代替author__name.
添加回答
舉報(bào)