discord.py文档有一个spotify类(https://discordpy.readthedocs.io/en/stable/api.html#spotify),我想知道如何将此活动设置为概要文件。文档中没有示例。我尝试在on_ready事件中使用此活动。
@client.event
async def on_ready():
print("Bot was connected to the server")
await bot.change_presence(activity=discord.Spotify(title = "Test"))我的输出是错的。
Bot was connected to the server
Ignoring exception in on_ready
Traceback (most recent call last):
File "/home/runner/Russian-field-of-experiments-on-the-island-of-Python/venv/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "main.py", line 13, in on_ready
await bot.change_presence(activity=discord.Spotify(title = "Test"))
File "/home/runner/Russian-field-of-experiments-on-the-island-of-Python/venv/lib/python3.8/site-packages/discord/activity.py", line 527, in __init__
self._sync_id = data.pop('sync_id')
KeyError: 'sync_id'完整源代码:
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="!")
@bot.event
async def on_ready():
print("Bot was connected to the server")
await bot.change_presence(activity=discord.Spotify(title = "Test"))
bot.run("token")如何在discord.py中使用Spotify类?
发布于 2022-04-04 20:41:00
要将机器人的状态更改为"listening to Spotify",可以这样做:
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="Spotify"))如果要将其设置为特定用户正在侦听的内容,可以这样做:
from discord import Spotify
@bot.event
async def on_ready():
user = bot.get_user(user_id) # Make sure to change this to the users ID.
while True:
for activity in user.activities:
if isinstance(activity, Spotify):
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name=f"{activity.title} by {activity.artist}"))
else:
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name=f"Nothing")) # User isn't listening to Spotify要使上述操作正常运行,您定义的用户必须侦听Spotify。如果他们不收听Spotify,则状态将更改为Nothing。
https://stackoverflow.com/questions/71743303
复制相似问题