如何在discord.py命令中允许多个可能的响应? [英] How do I allow for multiple possible responses in a discord.py command?
问题描述
我正在尝试建立Discord僵尸程序,但对于discord.py(实际上是Python 3)来说还比较陌生.我要添加命令"greet",这将提示用户说"hello".它只响应"hello",但是,当我希望它同时响应"hello"和"Hello"时.
I'm attempting to set up a Discord bot while being relatively new to discord.py (and in reality, Python 3). I want to add the command "greet", which will prompt the user to say "hello" to it. It only responds to "hello", however, when I want it to respond to both "hello" and "Hello".
我唯一想解决的问题就是将它们放在或语句中,从理论上讲,这应该使Python 3和bot在两个响应之间进行选择(如下所示).
The only things I could think about fixing it was placing them in an or
statement, which in theory should've made Python 3 and the bot choose between the two responses (as shown below).
@client.event
async def on_message(message):
if message.content.startswith('~greet'):
await client.send_message(message.channel, 'Say hello')
msg = await client.wait_for_message(author=message.author, content=('hello' or 'Hello'))
await client.send_message(message.channel, 'Hello.')
我拥有的原始代码很简单,只允许 hello
的一个响应.
The original code I had for it was simple and only allowed for the one response of hello
.
@client.event
async def on_message(message):
if message.content.startswith('~greet'):
await client.send_message(message.channel, 'Say hello')
msg = await client.wait_for_message(author=message.author, content=('hello' or 'Hello'))
await client.send_message(message.channel, 'Hello.')
出于某种原因,我无法缠住脑袋,它仍然无法识别'hello'
,并且只允许我说'hello'
作为回应.
For some reason I can't wrap my head around, it's still not recognizing 'Hello'
, and only ever allowing me to say 'hello'
in response.
推荐答案
or
的行为与您的想法不符.在传递给 wait_for_message
之前,先评估'hello'或'Hello'
,它等于'hello'
.
or
doesn't behave how you think it does. 'hello' or 'Hello'
is evaluated before being passed to wait_for_message
, and is equal to 'hello'
.
相反,您可以为 wait_for_message
提供一个 check
函数:
Instead, you can provide a check
function to wait_for_message
:
def is_hello(message):
return message.content.lower() == 'hello'
msg = await client.wait_for_message(author=message.author, check=is_hello)
这篇关于如何在discord.py命令中允许多个可能的响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!