我尝试在 discord 中用 pycharm 编写一个随机响应机器人,它确实有效,但是有一个小问题

问题描述 投票:0回答:1

问题是,如果您说出请求的单词,但带有一个额外的字母、单词或短语,它就会忽略它。

在 pycharm 中,我创建了 3 个文件,但最重要的是随机响应,这里是随机响应的代码:

def get_response(消息:str)-> str: p_message = message.lower()

if p_message == '@Madrid':
    return 'Reduce on pinging him, wait until he comes online and ask him what you wanted to ask.'

if message == '@madridddsta':
    return 'Reduce on pinging him, wait until he comes online and ask him what you wanted to ask.'

if p_message == 'madridddsta#7819':
    return 'Reduce on pinging him, wait until he comes online and ask him what you wanted to ask.'

if p_message == '<@949798747586584647>':
    return 'Reduce on pinging him, wait until he comes online and ask him what you wanted to ask.'

if p_message == '@XTREditz':
    return 'Reduce on pinging him, wait until he comes online and ask him what you wanted to ask.'

if message == '@XTREditz#6250':
    return 'Reduce on pinging him, wait until he comes online and ask him what you wanted to ask.'

if p_message == '<@841488565225390080>':
    return 'Reduce on pinging him, wait until he comes online and ask him what you wanted to ask.'
python discord pycharm bots
1个回答
0
投票

我什至不明白你想做什么。据我所知,您似乎正在检查一个字符串是否等于另一个字符串,而您想要检查一个字符串是否在另一个字符串中。例如:

# Instead of this ❌
if message == '@madridddsta':
    # ...

# Try this! ✔️
if '@madridddsta' in message:
    # ...
© www.soinside.com 2019 - 2024. All rights reserved.