(PyCharm) Discord 机器人(用 python 编写)如果 message.content.lowe() 中的“Hello”:不响应

问题描述 投票:0回答:1
import discord, os

TOKEN = 'I CANT POST IT IN THE FORM'

intents = discord.Intents.default()

intents.message_content = True
intents.members = True
intents.messages = True

client = discord.Client(intents=intents)


@client.event
async def on_ready():
    print('We have Logged in as {0.user}'.format(client))

    @client.event
    async def on_message(message):
        if message.author == client.user:
            return

        if message.content.startswith('$hello'):

            await message.channel.send('Hello!')

            if "Hello" in message.content.lower():

                await message.channel.send('i found hello in the message,SUCSESS!')

client.run(TOKEN)

在服务器中输入$hello时

discord 机器人返回:你好!

输入 hello/Hello 时

discord 机器人没有响应。

代码是从replit toturial复制的,所以有些东西可能会有所不同并且不起作用。

python discord pycharm discord.py bots
1个回答
0
投票

您实际上是在检查“Hello”是否等于“hello”,这当然是

false

你应该这样做:

if "hello" in message.content.lower():
    await message.channel.send('i found hello in the message,SUCSESS!')

或者如果你真的(我的意思是“真的”)想在 if 语句中保留“Hello”,也可以将其降低:

if "Hello".lower() in message.content.lower():
    await message.channel.send('i found hello in the message,SUCSESS!')
© www.soinside.com 2019 - 2024. All rights reserved.