【发布时间】:2021-10-23 18:27:03
【问题描述】:
我一直在处理我的不和谐机器人验证码的问题。验证码的效果非常好,但是如果他们验证了添加角色,我会感到很震惊
handledPromiseRejectionWarning: TypeError: Cannot read property 'add' of undefined
这是我的代码:
const Discord = require('discord.js-12');
const client = new Discord.Client();
const prefix = 'ri-';
const Captcha = require("@haileybot/captcha-generator");
client.once('ready', () => {
console.log('Ready!');
});
let captcha = new Captcha();
console.log(captcha.value);
const path = require("path"),
fs = require("fs")
client.on('message', async message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'verification') {
let captcha = new Captcha();
message.channel.send(
"**Enter the text shown in the image below:**",
new Discord.MessageAttachment(captcha.JPEGStream, "captcha.jpeg")
);
let collector = message.channel.createMessageCollector(m => m.author.id === message.author.id);
collector.on("collect", m => {
if (m.content.toUpperCase() === captcha.value){ message.channel.send("Verified Successfully!");
let role = message.guild.roles.cache.find(r => r.id === "Verified");
message.author.roles.add(role);
}else{ message.channel.send("Failed Verification!");}
collector.stop();
});
}
});
client.login('you don't need this.');
感谢任何帮助! ^^
【问题讨论】:
-
message.author返回不具有角色的不和谐用户。你想要一个 Discord 会员,让会员使用message.member代替 -
TypeError [INVALID_TYPE]:提供的角色不是角色、雪花或数组或角色或雪花的集合。当我尝试时它给了我这个错误。
标签: javascript discord.js undefined