Discord.py:如何使用 discord.Profile.connected_accounts [英] Discord.py: How to use discord.Profile.connected_accounts
问题描述
我已经尝试让它工作好几个小时了,我希望我的不和谐机器人能够简单地查看并返回目标帐户拥有的连接帐户(YouTube、Twitch、Spotify 等),我已经让它输出一些东西但我对此无能为力;需要一个解决方案.
I have been trying to get this to work for hours now, I want my discord bot to simply view and return what connected accounts a target account has (YouTube, Twitch, Spotify etc.), I have gotten it to output something but I can't do anything with it; need a solution.
import discord
from discord import Intents, Profile
from discord.ext import commands
client = commands.bot(command_prefix = '!', intents = Intents.all())
token = 'abc123asdfghjkl;...'
@client.command()
async def hl(ctx, user: discord.Member = None):
if user is None:
user = ctx.author
accounts = discord.user.Profile.connected_accounts
print(accounts)
client.run(token)
输出:'<_collections._tuplegetter object at 0x000001C807BB9370>'
Output: '<_collections._tuplegetter object at 0x000001C807BB9370>'
这是我正在使用的库的文档:https://discordpy.readthedocs.io/en/latest/api.html#discord.Profile.connected_accounts
Here is the documentation for the library I'm working with: https://discordpy.readthedocs.io/en/latest/api.html#discord.Profile.connected_accounts
它说它返回一个字典列表,但我不知道如何处理它输出的这个 tuplegetter 对象,我希望它输出类似这样的东西:
It says it returns a list of dicts but I don't know what to do with this tuplegetter object that it outputs, I would love for it to output something like this instead:
'[{type":twitch",id":92473777",name":discordapp"}]'
'[{"type": "twitch", "id": "92473777", "name": "discordapp"}]'
推荐答案
你在这里引用类本身,而不是实例,user
参数已经是 discord.成员
对象,然后你可以简单地做:
You're referencing to the class itself there, not to an instance, the user
argument is already a discord.Member
object, you can then simply do:
profile = await user.profile()
accounts = profile.connected_accounts
另外,机器人不能使用这个功能
Also, bots cannot use this function
这篇关于Discord.py:如何使用 discord.Profile.connected_accounts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!