大佬教程收集整理的这篇文章主要介绍了AutoMod 没有读取正确的单词,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试向我的 discord 机器人添加一个 automod cog。我在不同的文件中编写了黑名单命令和白名单命令,它们工作正常。我无法弄清楚的是,当它从 .csv 文件加载列入黑名单的单词时,它会将它们加载到变量中作为 ["['Test']"] 而不是作为测试。如果有人知道如何解决这个问题,请告诉我。
class autoMod(commands.Cog):
def __init__ (self,bot):
self.bot = bot
self.words = Words
@commands.Cog.Listener()
async def on_ready(self):
self.words = {}
with open(Wdir,'r') as csv_file:
csvreader=csv.reader(csv_filE)
for line in csvreader:
Words.append(str(linE))
print(f'autoMod {Words}')
@commands.Cog.Listener()
async def on_message(self,messagE):
print(Words)
if str(Words) in message.content:
await message.delete()
await message.chAnnel.send(f'{message.author.mention},You are not allowed to say that')
else:
pass
定义设置(机器人): bot.add_cog(autoMod(bot))
你可以这样做:
filtered_words = ["badword","verybadword"]
@client.event
async def on_message(messagE):
for word in filtered_words:
if word in message.content:
await message.delete()
await message.chAnnel.send("This word is blacklisted")
await client.process_commands(messagE)
现在机器人将删除包含任何过滤词的消息。 Bot 还会发送一条消息,说单词已被列入黑名单。
以上是大佬教程为你收集整理的AutoMod 没有读取正确的单词全部内容,希望文章能够帮你解决AutoMod 没有读取正确的单词所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。