![](/img/trans.png)
[英]How do I make my discord bot respond when a specific user sends a message in the channel?
[英]How do I respond to a Discord bot?
我想問機器人一個問題,然后再次回復它,而不必創建多個答案。 這是開始:
import discord
client = discord.Client()
@client.event
async def on_ready():
print("Bot is ready")
@client.event
async def on_message(message):
if message.author == client.user
return
msgs = message.content.startswith
然后我想創建一個聊天鏈。 像這樣:
if msgs("Restart")
await message.channel.send("Are you sure?")
if msgs("Yes")
await message.channel.send("Ok")
#once the bot has asked if im sure. I want to be able to reply yes
目前尚不清楚您到底想實現什么,但似乎您想使用wait_for
事件。 這會讓機器人知道它正在等待與您的代碼中的消息內容相同的用戶消息。
這是一個簡單的例子,還要確保將檢查 function 更改為您需要的方式,或者將其省略,它只是為了確保使用該命令的作者應該觸發wait_for
,但在您的情況下,您可以不需要它。
msg = await client.wait_for('message',timeout=10,check=lambda message: message.author == message.author)
if msg.content.lower() == "yes":
await message.channel.send("I'm restarting")
if msg.content.lower() == "no":
await message.channel.send("Cancelled!")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.