Я создаю чат-фильтр для своего бота, который будет разобщать людей, и два раза предупредит людей, прежде чем их запретить, если они скажут плохое слово. Я знаю, что есть лучшие способы сделать это, но, пожалуйста, не цитируйте их, поскольку я не хочу перекодировать весь мой бот. Вот мой фильтр чата (я заменил ругательные слова на «цензурированные»):
@bot.event
async def on_message(message):
global warn_count
if "censored" in message.content:
channel = await message.author.create_dm()
warn_count = warn_count + 1
if warn_count == 2:
print("Innapropriate language detected, given two warnings, message: {}, banned {}.".format(message.content,message.author)
await channel.send("That was your second warning. You have been kicked until further notice.")
await message.author.ban()
else:
print("Innapropriate language detected, by {}, message: {}, warned.".format(message.author,message.content))
await channel.send("WARNNG: please do not {} it is against our rules. If you do this again you will be kicked until further notice. If you believe this is an error please dm e at wolverhulk13#1112")
if "censored" in message.content:
channel = await message.author.create_dm()
warn_count = warn_count + 1
if warn_count == 2:
print("Innapropriate language detected, given two warnings, message: {}, banned {}.".format(message.content,message.author)
await channel.send("That was your second warning. You have been kicked until further notice.")
await message.author.ban()
else:
print("Innapropriate language detected, by {}, message: {}, warned.".format(message.author,message.content))
await channel.send("WARNNG: please do not swear it is against our rules. If you do this again you will be kicked until further notice. If you believe this is an error please dm me at wolverhulk13#1112")
if "censored" in message.content:
channel = await message.author.create_dm()
warn_count = warn_count + 1
if warn_count == 2:
print("Innapropriate language detected, given two warnings, message: {}, banned {}.".format(message.content,message.author))
await channel.send("That was your second warning. You have been kicked until further notice.")
await message.author.ban()
else:
print("Innapropriate language detected, by {}, message: {}, warned.".format(message.author,message.content))
await channel.send("WARNNG: please do not swear it is against our rules. If you do this again you will be kicked until further notice. If you believe this is an error please dm me at wolverhulk13#1112")
if "censored" in message.content:
channel = await message.author.create_dm()
warn_count = warn_count + 1
if warn_count == 2:
print("Innapropriate language detected, given two warnings, message: {}, banned {}.".format(message.content,message.author))
channel.send("That was your second warning. You have been kicked until further notice.")
await message.author.ban()
else:
print("Innapropriate language detected, by {}, message: {}, warned.".format(message.author,message.content))
await channel.send("WARNNG: please do not swear it is against our rules. If you do this again you will be kicked until further notice. If you believe this is an error please dm me at wolverhulk13#1112")
if "censored" in message.content.split(" "):
channel = await message.author.create_dm()
warn_count = warn_count + 1
if warn_count == 2:
print("Innapropriate language detected, given two warnings, message: {}, banned {}.".format(message.content,message.author))
await channel.send("That was your second warning. You have been kicked until further notice.")
await message.author.ban()
else:
print("Innapropriate language detected, by {}, message: {}, warned.".format(message.author,message.content))
await channel.send("WARNNG: please do not swear it is against our rules. If you do this again you will be kicked until further notice. If you believe this is an error please dm me at wolverhulk13#1112")
if "censored" in message.content.split(" "):
warn_count = warn_count + 1
channel = await message.author.create_dm()
if warn_count == 2:
print("Innapropriate language detected, given two warnings, message: {}, banned {}.".format(message.content,message.author))
await channel.send("That was your second warning. You have been kicked until further notice.")
await message.author.ban()
else:
await channel.send("WARNNG: please do not swear it is against our rules. If you do this again you will be kicked until further notice. If you believe this is an error please dm me at wolverhulk13#1112")
print("Innapropriate language detected, by {}, message: {}, warned.".format(message.author,message.content))
if "censored" in message.content:
channel = await message.author.create_dm()
warn_count = warn_count + 1
if warn_count == 2:
print("Innapropriate language detected, given two warnings, message: {}, banned {}.".format(message.content,message.author))
await channel.send("That was your second warning. You have been kicked until further notice.")
await message.author.ban()
else:
print("Innapropriate language detected, by {}, message: {}, warned.".format(message.author,message.content))
await channel.send("WARNNG: please do not swear it is against our rules. If you do this again you will be kicked until further notice. If you believe this is an error please dm me at wolverhulk13#1112")
if "censored" in message.content:
channel = await message.author.create_dm()
warn_count = warn_count + 1
if warn_count == 2:
print("Innapropriate language detected, given two warnings, message: {}, banned {}.".format(message.content,message.author))
await channel.send("That was your second warning. You have been kicked until further notice.")
await message.author.ban()
else:
print("Innapropriate language detected, by {}, message: {}, warned.".format(message.author,message.content))
await channel.send("WARNNG: please do not swear it is against our rules. If you do this again you will be kicked until further notice. If you believe this is an error please dm me at wolverhulk13#1112")
if "censored" in message.content:
channel = await message.author.create_dm()
warn_count = warn_count + 1
if warn_count == 2:
print("Innapropriate language detected, given two warnings, message: {}, banned {}.".format(message.content,message.author))
await channel.send("That was your second warning. You have been kicked until further notice.")
await message.author.ban()
else:
print("Innapropriate language detected, by {}, message: {}, warned.".format(message.author,message.content))
await channel.send("WARNNG: please do not swear it is against our rules. If you do this again you will be kicked until further notice. If you believe this is an error please dm me at wolverhulk13#1112")
if "censored" in message.content:
channel = await message.author.create_dm()
warn_count = warn_count + 1
if warn_count == 2:
print("Innapropriate language detected, given two warnings, message: {}, banned {}.".format(message.content,message.author))
await channel.send("That was your second warning. You have been kicked until further notice.")
await message.author.ban()
else:
print("Innapropriate language detected, by {}, message: {}, warned.".format(message.author,message.content))
await channel.send("WARNNG: please do not swear it is against our rules. If you do this again you will be kicked until further notice. If you believe this is an error please dm me at wolverhulk13#1112")
else:
global message_counter
message_counter = message_counter + 1
print(message_counter)
await bot.process_commands(message)
возвращает ошибку: File "bot.py", line 25
await channel.send("That was your second warning. You have bee---
^
SyntaxError: invalid syntax