如何禁止某些词然后删除消息
How To Ban Certain Words And Then Delete Messages
我的目标是检查用户在 discord 频道中输入的内容是否包含列表中的特定单词或短语,如下所示:
illegal_words = ["apple", "pear", "banana"]
预期的结果是,当我键入的内容包含以下一个或多个词时,它会看到该词,然后将其删除,然后发送一条消息,指出您不能输入该特定消息。
这是我当前的代码,其中包含列表
client = commands.Bot(command_prefix="..")
illegal_words = ["apple", "pear", "banana"]
@client.event
async def on_message(ctx):
[word in message.content for word in illegal_words]
any([word in message.content for word in illegal_words])
await ctx.channel.purge(limit=1)
await ctx.send("""That Word Is Not Allowed To Be Used!
Continued Use Of Mentioned Word Would Lead To Punishment!""")
@client.event
async def on_message(message):
if any(word in message.content for word in illegal_words):
await message.delete()
await message.channel.send("""That Word Is Not Allowed To Be Used! Continued Use Of Mentioned Word Would Lead To Punishment!""")
else:
await client.process_commands(message)
on_message
收到一个 Message
对象,而不是 Context
。我们可以直接删除该消息,并且应该通过发送消息到它所在的频道来响应它。
我的目标是检查用户在 discord 频道中输入的内容是否包含列表中的特定单词或短语,如下所示:
illegal_words = ["apple", "pear", "banana"]
预期的结果是,当我键入的内容包含以下一个或多个词时,它会看到该词,然后将其删除,然后发送一条消息,指出您不能输入该特定消息。
这是我当前的代码,其中包含列表
client = commands.Bot(command_prefix="..")
illegal_words = ["apple", "pear", "banana"]
@client.event
async def on_message(ctx):
[word in message.content for word in illegal_words]
any([word in message.content for word in illegal_words])
await ctx.channel.purge(limit=1)
await ctx.send("""That Word Is Not Allowed To Be Used!
Continued Use Of Mentioned Word Would Lead To Punishment!""")
@client.event
async def on_message(message):
if any(word in message.content for word in illegal_words):
await message.delete()
await message.channel.send("""That Word Is Not Allowed To Be Used! Continued Use Of Mentioned Word Would Lead To Punishment!""")
else:
await client.process_commands(message)
on_message
收到一个 Message
对象,而不是 Context
。我们可以直接删除该消息,并且应该通过发送消息到它所在的频道来响应它。