【问题标题】:How make custom status discord.py如何制作自定义状态 discord.py
【发布时间】:2020-05-20 03:24:57
【问题描述】:

为什么我的代码不起作用?

@bot.event
async def on_ready():
    print('Bot is now working!')
    await bot.change_presence(activity=discord.CustomActivity(name='Custom status' ,emoji='????️'))

然后给我一个错误。

Ignoring exception in on_ready
Traceback (most recent call last):
  File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/discord/client.py", line 270, in _run_event
    await coro(*args, **kwargs)
  File "main.py", line 30, in on_ready
    await bot.change_presence(activity=discord.CustomActivity(name='Custom status' ,emoji='????️'))
AttributeError: module 'discord' has no attribute 'CustomActivity'

如何修复错误?

【问题讨论】:

  • 你用的是什么版本的discord包?
  • 我使用的是最新版本 1.3。
  • 您的路径中是否有另一个名为“discord”的模块,即文件或文件夹?
  • 机器人无法使用自定义状态,只能使用之前的PlayingWatching等。
  • 您可以通过在机器人的开头添加 print(discord.__version__) 来仔细检查版本是否正确更新。

标签: python python-3.x discord discord.py


【解决方案1】:

我迟到了, WayToDoor 是对的,机器人不能使用自定义状态,我发现他们“可以使用它”但它是不可见的,除了机器人可以看到它是自定义状态并且您会在机器人配置文件上看到“自定义状态”。

机器人可以播放、观看、收听和流式传输,没问题

您现在还可以选择使用类型 5 的“竞争”。我在文档中还看不到它,所以我假设它还没有实现。

#this is how "Competing in" is set.
discord.Activity(name="Test", type=5)

这应该可以。

【讨论】:

    【解决方案2】:

    机器人还不能使用自定义状态。请改用PlayingWatching。见https://github.com/Rapptz/discord.py/issues/2400

    【讨论】:

    • 可以确认这仍然是一个持续存在的问题。
    • 曾经有一段时间,机器人可以使用自定义状态,使用 discord.ActivityType.custom,并使用状态而不是名称来定义文本。
    【解决方案3】:

    试试这些:

    # Setting `Playing ` status
    await bot.change_presence(activity=discord.Game(name="a game"))
    
    # Setting `Streaming ` status
    await bot.change_presence(activity=discord.Streaming(name="My Stream", url=my_twitch_url))
    
    # Setting `Listening ` status
    await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="a song"))
    
    # Setting `Watching ` status
    await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="a movie"))
    

    【讨论】:

      【解决方案4】:

      试试这个:

      @bot.command(pass_context=True)
      async def Self_Clock(ctx):
          print("[+]: Status Changer Loaded")
          await ctx.message.delete()
          from datetime import datetime
          headers = {
              'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7',
              'Content-Type': 'application/json',
              'Authorization': token,
          }
          request = requests.Session()
          while True:
              now = datetime.now()
              current_time = now.strftime("%H:%M:%S")
              setting = {
                  'status': "online",
                  "custom_status": {"text": f"[+]: My current time: {current_time}"}
              }
              request.patch("https://canary.discordapp.com/api/v6/users/@me/settings",headers=headers, json=setting, timeout=10)
              time.sleep(1)
      

      【讨论】:

      • 如果没有,我为什么要添加它?
      猜你喜欢
      • 2021-03-01
      • 2021-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多