【问题标题】:NameError: 'discord' is not defined?NameError: 'discord' 没有定义?
【发布时间】:2020-08-29 19:29:42
【问题描述】:

这是针对我正在制作的不和谐机器人,我试图设置机器人的状态。我找到了一个看起来像 await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="for e/info")) 的答案,并将其放入 on_ready 事件函数中。但是,它给了我以下例外:

Ignoring exception in on_ready
Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", 
    line 312, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\user\OneDrive\Desktop\EffeKtive\bot.py", line 14, in on_ready
    await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="for 
      e/info"))
NameError: name 'discord' is not defined

我觉得我错过了import

【问题讨论】:

  • 您将不得不安装支持您找到的代码所需的任何模块。看起来你需要discord.py,然后你可以做import discord
  • 我已经有 discord.py。

标签: python discord discord.py


【解决方案1】:

您可能已在单独的位置安装了 discord.py,请尝试将其安装到 C:\Windows\system32>。您也可能缺少import。 如果您尝试添加命令,您还必须:from discord.ext import commands。 你可以发布你的代码吗?

【讨论】:

  • 我也不知道diggy是否回答了你的问题,它没有说它有支票所以我发布了这个。
【解决方案2】:

您需要在代码顶部添加import discord

【讨论】:

    猜你喜欢
    • 2021-11-09
    • 2020-09-20
    • 2020-01-17
    • 2018-10-06
    • 1970-01-01
    • 1970-01-01
    • 2019-07-05
    • 2014-06-05
    • 1970-01-01
    相关资源
    最近更新 更多