【问题标题】:Python discord bot how to check if a message contains a bad wordPython discord bot如何检查消息是否包含坏词
【发布时间】:2022-08-19 09:10:57
【问题描述】:

我正在尝试制作一个审核机器人,我不希望人们能够使用诽谤等,这就是我所拥有的:

async def on_message(message):
  if \"swear\" in message.content:
    await message.channel.send(\"Thats not nice!\")
    await message.delete()

但这不起作用

  • 为什么它不起作用?有什么错误(如果有的话)?
  • 它只是不工作,什么都没有发生
  • 也许message_content 意图未启用?尝试print(message) 以查看事件是否实际运行。 (也可以通过 ping 机器人来尝试)
  • 我试过了,它不起作用
  • 请包括完整的代码,问题可能在其他地方

标签: python discord


【解决方案1】:

这里:

import discord
import os
from webserver import keep_alive


my_secret = os.environ['TOKEN']

client = discord.Client()

@client.event
async def on_ready():
    print("{0.user} is now online!".format(client))
@client.event
async def on_message(message):
  if message.author == client.user:
    return
  elif message.content.startswith("!gecko"):
    await message.channel.send("https://steamcommunity.com/sharedfiles/filedetails/?id=2829941620")
  elif message.content.startswith("!r56"):
    await message.channel.send("https://steamcommunity.com/sharedfiles/filedetails/?id=820260968")
  elif message.content.startswith("!playerlead"):
    await message.channel.send("https://steamcommunity.com/sharedfiles/filedetails/?id=846066944")
  elif message.content.startswith("!eu4"):
    await message.channel.send("https://store.steampowered.com/app/236850/Europa_Universalis_IV/")
  elif message.content.startswith("!hoi4"):
    await message.channel.send("https://store.steampowered.com/app/394360/Hearts_of_Iron_IV/")
  elif message.content.startswith("!help"):
    await message.channel.send("Use Gecko, \n r56 \n playerlead \n eu4 \n or hoi4")
async def on_message(msg):
  if "whats up" in msg.content:
    print("hello")
    await msg.channel.send("Use Gecko, \n r56 \n playerlead \n eu4 \n or hoi4")




keep_alive()
client.run(my_secret)

【讨论】:

    猜你喜欢
    • 2017-07-18
    • 2023-04-02
    • 2021-03-27
    • 2019-11-23
    • 2019-03-23
    • 2021-10-30
    • 1970-01-01
    • 2022-01-07
    • 1970-01-01
    相关资源
    最近更新 更多