Answer the question
In order to leave comments, you need to log in
The bot ignores the trigger if there is a space in the message, how to fix it?
I want to make triggers to which the bot will respond with a message, it worked, but if the message for which there is a space, then the bot does not see it, how to fix it?
GoodNight = ['Доброй ночи']
BotMen = ['Бот', 'Bot']
@Bot.event
async def on_message(message):
if message.author == Bot.user:
return
else:
content = message.content.split()
for word in content:
if word in GoodNight:
await message.channel.send('Ты уже уходишь или это ночное приветствие? %s' % Bot.get_emoji(755856809436250253))
if word in BotMen:
await message.channel.send('Да, я вас слушаю %s' % Bot.get_emoji(810645595089535087))
await Bot.process_commands(message)
Answer the question
In order to leave comments, you need to log in
The best solution would be:
goodNight = ['доброй ночи']
botMen = ['бот', 'bot']
# пишем все строки в нижнем регистре
# (маленькими буквами) для корректного сравнения в будущем
@Bot.event
async def on_message(message, txt: message.content, send: message.channel.send): # упрощаем себе жизнь
if message.author == Bot.user:
return
else:
content = " ".join(txt.lower().split())
"""
строкой выше мы из " ДоБрой НочИ " делаем "доброй ночи"
то есть убираем лишние пробелы в начале и в конце
и приводим к нижнему регистру для корректного сравнения"""
if content in goodNight:
await send('Ты уже уходишь или это ночное приветствие? %s' % Bot.get_emoji(755856809436250253))
if content in botMen:
await send('Да, я вас слушаю %s' % Bot.get_emoji(810645595089535087))
await Bot.process_commands(message)
Dude, it's simple, your split splits the list into "Good" and "night", and then there is a check whether it is in the line, but whether it is in the list, and the line "Kind" is not in the list, there is only the line " Good night, I hope I explained it clearly. In short, in this case, you can remove the square brackets in the GoodNight variable (by the way, variables with a capital letter are not called in python) and everything will work
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question