亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Discord.py 如何使用機器人將發送的消息?

Discord.py 如何使用機器人將發送的消息?

藍山帝景 2023-09-12 16:31:33
import discordfrom discord.ext import commandsasync def anyfunc(ctx):    await ctx.send(f"{ctx.message.author.mention}, "Hi!")    bot_message_id = ((bot's_last_message)).id在 (()) 中放入什么以使機器人記住它將發送的消息的 ID?有沒有辦法將下一條(例如用戶的)消息(尚未發送)的 id 作為變量?
查看完整描述

2 回答

?
MMTTMM

TA貢獻1869條經驗 獲得超4個贊

ctx.send()返回discord.Message它發送的消息的實例,因此您可以將其存儲在變量中。


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

至于你的第二個問題,如果你想獲得用戶對該消息的響應(因此特定用戶將發送的下一條消息),你可以使用內置函數wait_for。


def check(message):

? ? return message.author.id == the_id_of_that_user


message = await bot.wait_for("message", check=check)

這樣,機器人實際上就會發出wait for一條消息,使您的check函數返回True,或者在本例中是由該用戶發送的消息。


查看完整回答
反對 回復 2023-09-12
?
繁華開滿天機

TA貢獻1816條經驗 獲得超4個贊

我不太明白你的問題,但我會盡力回答。根據API 參考,您可以使用 獲取某人的最后一條消息channel.history().get()。這是一個例子:

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

這可能會起作用,但如果出現錯誤,也許您可以嘗試author__id=bot's id代替author__name.


查看完整回答
反對 回復 2023-09-12
  • 2 回答
  • 0 關注
  • 150 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號