我想让我的机器人“听”一些东西

时间:2021-05-07 09:38:10

标签: python discord discord.py bots

我正在尝试让我的不和谐机器人状态显示在听你说话。我尝试了我发现的各种方法。这是唯一一个没有让我的机器人停止工作的:

@client.event
    async def on_ready():
      client.user.setActivity('you', { type: 'LISTENING' });

这样我的机器人仍然在运行,但它没有显示状态。我也收到此错误消息:

Ignoring exception in on_ready
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "main.py", line 9, in on_ready
    client.user.setActivity('to you', { type: 'LISTENING' });
AttributeError: 'ClientUser' object has no attribute 'setActivity'

请问我忘了包含一些重要的东西。

1 个答案:

答案 0 :(得分:1)

阅读链接:

https://discordpy.readthedocs.io/en/stable/api.html#discord.Client.change_presence

https://discordpy.readthedocs.io/en/stable/api.html#discord.Client.activity

https://discordpy.readthedocs.io/en/stable/api.html#discord.ActivityType

https://discordpy.readthedocs.io/en/stable/api.html#discord.Spotify.type


setActivity 不存在。 ActivityType.listening 仅通过 discord.Spotify 存在。

您通过 change_presence 更改您的活动:

game = discord.Game("with the API")
await client.change_presence(status=discord.Status.idle, activity=game)

song = discord.Spotify(...)
await client.change_presence(status=discord.Status.idle, activity=song)

setActivity 来自 discord.js。然而,您正在使用 Python 进行编程,并且您使用的是 discord.py