【问题标题】:Discord bot in python is not recognizing commandspython 中的 Discord bot 无法识别命令
【发布时间】:2023-01-22 21:26:52
【问题描述】:

我的 discord 机器人刚刚工作了一段时间,但突然间它无法识别频道中的命令。 该机器人拥有频道的管理员权限,之前可以发送消息。

机器人上线,令牌正常工作。

` 导入不和谐 随机导入 导入平台 导入操作系统 导入异步 从 discord.ext 导入任务、命令

intents = discord.Intents.default()
intents.messages = True
client = discord.Client(command_prefix=commands.when_mentioned_or('.'), intents=intents)`

quotes = ["quote 1 ", "quote 2",]


@client.event
async def on_ready() -> None:
   print(f'{client.user} has connected to Discord!')
   print(f"discord.py API version: {discord.__version__}")
   print(f"Python version: {platform.python_version()}")
   print(f"Running on: {platform.system()} {platform.release()} ({os.name})")
   await update_status()


async def update_status():
    while True:
       await client.change_presence(status=discord.Status.online, activity=discord.Game(name="Deep Rock  Galactic"))
       await asyncio.sleep(10)


@client.event
async def on_message(message):

if message.author == client.user:
    return
if message.content == ".quote":
  print(message.author.id)
  try:
    quote = random.choice(quotes)
    await message.channel.send(quote)
    print("Executed command .quote")
  except ValueError as e:
    await message.channel.send(f'Command not working, reason: {e}')

if message.content == ".me":
  print(message.author.id)
  try:
    if message.author.id == "author id:
      quote = random.choice(quotes)
      await message.channel.send(quote)
      print("Executed command .me")
    else:
      await message.channel.send("Only user X can use this command")
    except ValueError as e:
    await message.channel.send(f'Command not working, reason: {e}')


client.run("TOKEN")`

更改了令牌,删除了 .me 功能并在没有它的情况下进行了尝试。

【问题讨论】:

    标签: python discord discord.py command bots


    【解决方案1】:

    它适用于我的 Linux VM。

    尝试在 VSCode 上运行它,但现在工作正常。 如果有人知道为什么它不能在我的电脑上正常工作,请告诉我。 可能与我的 discord.py 版本有关。

    【讨论】:

      猜你喜欢
      • 2018-08-15
      • 2022-07-12
      • 2021-11-10
      • 2020-08-15
      • 2018-10-21
      • 2021-03-01
      • 2021-04-11
      • 2021-06-15
      • 2019-03-05
      相关资源
      最近更新 更多