Discord.py:如何使用discord.Profile.connected_accounts [英] Discord.py: How to use discord.Profile.connected_accounts

查看:64
本文介绍了Discord.py:如何使用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对象位于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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆