javascript - 如何修复从 discord.js 中的集合中获取用户的问题?
问题描述
我正在尝试从集合中的 ID 中检索用户名(Discord.js)
我尝试使用 client.fetchUser(config.userID) 获取用户
const adm = client.fetchUser(config.admins)
const embed = new Discord.RichEmbed()
.setTitle("Developers")
.setDescription("Usernames: \n"+adm.username)
message.channel.send(embed);
它输出“userID1,userID2 不是雪花”
解决方案
文档说参数应该是雪花Snowflake Ref
从我所见,您传递了一系列不起作用的雪花。
该方法返回 User 类型的 Promise,我认为您正在尝试一次性获取所有用户。
我创建了一个代码片段,它将从您的管理员雪花数组中一个一个地获取用户,然后创建一个字符串供您输入您的消息。
请记住在 ASYNC 方法中使用它,否则await
会引发错误。
编辑:如评论中所述,您需要先初始化 adminUsers,然后才能推送到它。
let adminUsers = []; // array of Users
for (let i = 0; i < config.admins.length; i++) {
let currentUser = config.admins[i];
let user = await client.fetchUser(currentUser);
adminUsers.push(user);
}
let description = "Usernames: \n";
adminUsers.forEach(user => {
description += `${user.username}\n`;
});
const embed = new Discord.RichEmbed()
.setTitle("Developers")
.setDescription(description)
message.channel.send(embed);
推荐阅读
- python - 标准化或标准化离散变量?
- javascript - 画布和 JavaScript - 在等待按键输入时从右到左流动单词
- google-apps-script - 我们如何获取当前登录 google 帐户的用户 ID
- javascript - 如何在 DraftJS 中呈现带有标题的 Img
- flutter - 如何在颤振的本地化文件中转义单引号?
- flutter - NoSuchMethodError:getter 'stringValue' 在 null 上调用并冻结
- python - Networkx 图不是平面的
- angular - 用 fullcalendar 和 angular 8 解决问题
- c++ - 为什么它给出0答案?
- python - Pyqt5时间线在按下播放按钮时跳过帧