【发布时间】:2019-04-26 21:42:32
【问题描述】:
现在,我有以下内容:
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import os
bot = Bot(command_prefix="?")
with open("bad-words.txt") as file: # bad-words.txt contains one phrase per line
bad_words = [bad_word.strip().lower() for bad_word in file.readlines()]
@bot.event
async def on_message(message):
message_content = message.content.strip().lower()
async for bad_word in bad_words:
if bad_word in message:
await bot.send_message(message.channel, "{}, your message has been censored.".format(message.author.mention))
await bot.delete_message(message)
bot.run(os.getenv("TOKEN"))
我有这个 Python 代码,但它不起作用。我不知道为什么,因为我看不到当前托管情况的错误。
目标是让机器人删除包含bad-words.txt 中列入黑名单的短语的邮件,其中每行包含一个短语。
机器人运行,但不做任何事情。我在这里想念什么?谢谢!
【问题讨论】:
-
async for应该是普通的for。为什么看不到错误?
标签: python discord.py