gpt4 book ai didi

javascript - Discord.js 为 ReactionRole 添加一次 react 收集器

转载 作者:行者123 更新时间:2023-12-02 22:01:13 27 4
gpt4 key购买 nike

我正在尝试向我的机器人添加 react Angular 色功能。这意味着人们加入我的服务器,并且必须使用表情符号回复消息才能获得适当的 channel Angular 色。

我将机器人添加到服务器,权限为 8(管理员)。

这是日志:

Ready!
Emoji is 👍
Try to add Role Online to User *User*
Added *User*
(node:18801) UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Permissions
at item.request.gen.end (/home/ubuntu/node_modules/discord.js/src/client/rest/RequestHandlers/Sequential.js:85:15)
at then (/home/ubuntu/node_modules/snekfetch/src/index.js:215:21)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
(node:18801) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
(node:18801) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

这是我的代码:

client.once('ready', () => {

let messageID = '669575028605583390'
let guild = client.guilds.first()
let welcomeChannel = guild.channels.find(c => c.name === 'rulesNroles')
if (!welcomeChannel) return console.log("Couldn't find welcome channel.");
welcomeChannel.fetchMessage(messageID).then( message => {

const filter = (reaction) => {
return reaction.emoji.name === '👍';
};

const collector = message.createReactionCollector(filter, { });

collector.on('collect', (reaction, reactionCollector) => {
try {
console.log(`Emoji is ${reaction.emoji.name}`)
let role = guild.roles.find(r => r.name === 'Online');
reaction.users.forEach(u => {
if (u != client.user) {
console.log(`Try to add Role ${role.name} to User ${u.username}`)
try {
let member = guild.members.find(gm => gm.user.id === u.id);
let addedMember = member.addRole(role);
if (typeof addedMember != 'undefined') console.log(`Added ${member.user.username}`)
} catch(e) {
//console.log(e.stack);
}
}
});
} catch(e) {
console.log(e.stack);
}
});

collector.on('end', () => console.log('ended'));

});

console.log('Ready!');

return;
});

我在这里做错了什么?希望你能帮助我:)

最佳答案

您的机器人没有添加 Angular 色的权限。您可以通过添加如下所示的 catch block 来验证这一点:

let addedMember = member.addRole(role).catch(e => {
console.log(e);
});

此外,未定义是一个虚假对象,因此

if(addedMember) {

是一样的
if(typeof addedMember === undefined) {

以及同样的事情

if(addedMember === undefined) {

编辑:

您的机器人无法在 Angular 色列表中添加比其更高 Angular 色更高的 Angular 色,因此也请检查这一点。

希望这对您有帮助!

关于javascript - Discord.js 为 ReactionRole 添加一次 react 收集器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59868846/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com