更新时间:2023-11-19 11:33:46
由于您可能要等待搜索完成,因此可以更改 async for
到常规的 for
,如Patrick Haugh所述:
Since you probably want to wait for the search to finish, you could just change the async for
to a regular for
as mentioned by Patrick Haugh:
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)
在Python 3中, any()
方法可用于进一步简化此操作:
However, in Python 3, the any()
method can be used to simplify this further:
if any(bad_word in message for bad_word in bad_words):
await bot.send_message(message.channel, "{}, your message has been censored.".format(message.author.mention))
await bot.delete_message(message)