[英]Reply to a message discord.py
我想讓我的機器人在用戶輸入某個句子時對用戶消息做出反應。
我的回復代碼:
await ctx.message.reply("I just replied to you")
我得到錯誤:
ctx.message has no attribute "reply"
我可以執行什么代碼讓機器人回復消息?
當我說回復時,我的意思是用戶可以在消息上按回復
對於這里的任何新用戶,從1.6.0 discord.py-rewrite更新開始,您現在可以回復了!
每個discord.abc.Messageable
現在都有一個回復屬性。 要回復,只需使用
await ctx.reply('Hello!')
您也可以在回復中不提及作者, mention_author=False
await ctx.reply('Hello!', mention_author=False)
您還可以在此處找到一個基本示例
Discord.py 尚不支持新的“回復”功能。 不幸的是,除非他們將回復功能添加到庫中,否則您無法真正使用回復功能。
一種選擇是使用Cog.listener
,您可以在此處找到有關 Cog.listener 的文檔,但要回答您的問題,我使用 Cog.listener 的方式是:
@bot.listen('on_message')
async def stuff(message):
if message.content.startswith("buttlerprefix"): # this tells the bot what to listen for. If a user types `buttlerprefix` in any text channel, it will respond with what's below
msg = await message.channel.send("my prefix is `>`") # set the sending message equal to a variable so that you can manipulate it later like I did with the timer, and delete function below
await asyncio.sleep(10) # tells the bot to wait 10 seconds before continuing below
await msg.delete() # deletes the send message after 10 seconds
如果您還有其他問題,或者遇到我在這里沒有看到的任何錯誤,請與我聯系:)
嘗試用
await ctx.send('I just replied to you')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.