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复制的,所以有些东西可能会有所不同并且不起作用。
您实际上是在检查“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!')