如何制作自定义状态discord.py

lon*_*cer 2 python python-3.x discord discord.py

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

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

并给我一个错误。

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'
Run Code Online (Sandbox Code Playgroud)

错误是如何修复的?

小智 7

我迟到了,WayToDoor 是对的,bots 不能使用自定义状态,我发现他们“可以使用它”但它是不可见的,除了 bots 可以看到它是一个自定义状态,你会在机器人简介。

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

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

#this is how "Competing in" is set.
discord.Activity(name="Test", type=5)
Run Code Online (Sandbox Code Playgroud)

这应该有效。


Way*_*oor 5

机器人尚不能使用自定义状态。使用PlayingWatching代替。请参阅https://github.com/Rapptz/discord.py/issues/2400