Discord API - 使用 public_flags 获取用户的徽章
Posted
技术标签:
【中文标题】Discord API - 使用 public_flags 获取用户的徽章【英文标题】:Discord API - Get user's badges using public_flags 【发布时间】:2021-12-05 21:37:45 【问题描述】:我正在使用 javascript,我正在寻找如何获取用户拥有的标志列表(来自 public_flags)作为示例:
[
"House Bravery",
"Partnered Server Owner",
"Early Verified Bot Developer"
]
我没有使用 discord.js
【问题讨论】:
【参考方案1】:如果您尝试从用户对象中获取它们,则此方法有效 -
await user.fetchFlags().toArray() // would return an array as you require
【讨论】:
【参考方案2】:我发现了如何使用 vanilla javascript 来实现它:
var badges = [];
var flags = response.public_flags
flags = response.public_flags
if ((flags & badges2.Discord_Employee) == badges2.Discord_Employee)
badges.push("Discord Employee")
if ((flags & badges2.Early_Supporter) == badges2.Early_Supporter)
badges.push("Early Supporter")
if ((flags & badges2.House_Balance) == badges2.House_Balance)
badges.push("House Balance")
if ((flags & badges2.House_Brilliance) == badges2.House_Brilliance)
badges.push("House Brilliance")
if ((flags & badges2.House_Bravery) == badges2.House_Bravery)
badges.push("House Bravery")
if ((flags & badges2.Bug_Hunter_Level_1) == badges2.Bug_Hunter_Level_1)
badges.push("Bug Hunter LVL.1")
if ((flags & badges2.Bug_Hunter_Level_2) == badges2.Bug_Hunter_Level_2)
badges.push("Bug Hunter LVL.2")
if ((flags & badges2.Early_Verified_Bot_Developer) == badges2.Early_Verified_Bot_Developer)
badges.push("Verified Bot Dev")
if ((flags & badges2.HypeSquad_Events) == badges2.HypeSquad_Events)
badges.push("HypeSquad Events")
if ((flags & badges2.Partnered_Server_Owner) == badges2.Partnered_Server_Owner)
badges.push("Partnered Server Owner")
【讨论】:
以上是关于Discord API - 使用 public_flags 获取用户的徽章的主要内容,如果未能解决你的问题,请参考以下文章