【问题标题】:How can I make my discord bot respond with a "follow up" message如何让我的不和谐机器人回复“跟进”消息
【发布时间】:2021-03-05 01:05:22
【问题描述】:
我是 discord.py 的初学者,正在努力寻找答案。
我想让我的不和谐机器人在我发送“message1”之后仅响应“message2”。
例如,
@client.event
async def on_message(message):
if message.content.lower() == '!rps':
await message.channel.send("Input your choice!")
在这里,我希望用户输入 !rps ,然后我想检查他对石头/纸/剪刀的后续响应,并让机器人做出相应的回复。用户输入“!rps”后如何让机器人等待用户的下一条消息
【问题讨论】:
标签:
python
discord
discord.py
【解决方案1】:
您可以通过wait_for函数让机器人等待用户输入!
async def on_message(message):
if message.content.lower() == '!rps':
await message.channel.send("Input your choice!")
def check(m):
return m.content in ['rock','paper','scissors'] and m.channel == channel and m.author == message.author
msg = await client.wait_for('message', check=check)
#msg variable stores the new user input(rock/paper/scissors) [your code down]
await channel.send(f'User Choosed {msg.content}')
在上面的代码中,我使用了wait_for 函数来等待用户输入!在检查功能的帮助下,我用来检查输入是否有效,输入是否由正确的作者和正确的频道进行!如果一切都有效,它开始执行剩余的代码