【发布时间】:2020-04-06 14:52:24
【问题描述】:
我正在为我的不和谐机器人制作一个聊天过滤器,如果人们说坏话,它会在禁止他们之前警告他们两次。我知道有更好的方法可以做到这一点,但请不要引用它们,因为我不想重新编码我的整个机器人。这是我的聊天过滤器(我已将 cuss 词替换为“censored”):
@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
【问题讨论】:
-
. . . banned {}.".format(message.content,message.author)print 的右括号。 VTC 是一个错字。
标签: python filter bots discord discord.py