【发布时间】:2021-01-16 18:36:58
【问题描述】:
我正在制作一个阻止脏话的 Discord 机器人。它可以通过使用下划线和/或附加到脏话的其他符号来绕过。
如何让脚本仍然阻止这些单词但一般不删除字符?
这是我的代码:
import discord
import random
import string
from discord.ext import commands
client = commands.Bot(command_prefix = 'as-')
with open("badwords2.txt") as file:
bad_words = file.read().splitlines()
def check_if_allowed(text):
allowed_characters = string.ascii_uppercase + string.ascii_lowercase
if character not in allowed_characters:
return False
return True
@client.event
async def on_message(message):
for bad_word in bad_words:
if bad_word in message.content.lower().split(" "):
t = discord.Embed(color=0x039e00, title="Message Removed", description=":x: Please do not swear. Swearing can result in a mute or ban.")
t.set_footer(text="DM TheSuperRobert2498#2498 for bot suggestions.")
await message.channel.send(embed=t)
await message.delete()
return
if not check_if_allowed(message.content):
t = discord.Embed(color=0x039e00, title="Message Removed", description=":x: Please do not swear. Swearing can result in a mute or ban.")
t.set_footer(text="DM TheSuperRobert2498#2498 for bot suggestions.")
await message.channel.send(embed=t)
await message.delete()
return
client.run('TOKEN')
【问题讨论】:
标签: python discord discord.py substring