gpt4 book ai didi

javascript - 未处理的PromiseRejectionWarning : TypeError: Cannot read property 'add' of undefined (Discord Bot)

转载 作者:行者123 更新时间:2023-12-04 07:14:06 25 4
gpt4 key购买 nike

我一直在处理我的不和谐机器人验证码问题。验证码真的很好用,但是在添加 Angular 色时,如果他们验证它会打我一巴掌

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 指的是一个没有 Angular 色的用户。改用 message.member
  • 用 r.name 替换 r.id,id 不是字符串。

  • 祝你有美好的一天 :)

    关于javascript - 未处理的PromiseRejectionWarning : TypeError: Cannot read property 'add' of undefined (Discord Bot),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68892003/

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