我的Discord机器人遇到了问题, 我试图使我的机器人可配置,但是Keyv出现问题(这是我用来保存数据的方式)
我尝试创建一个“ Setwelcome”命令 以便该机器人欢迎新用户。 我希望这种欢迎是可配置的
这些是配置功能
if(message.content.startsWith(prefix + "setwelcome")) {
if(!message.member.hasPermission("ADMINISTRATOR")) return message.reply("Tu no puedes hacer eso, ¿Porque no le hablas a un admin?");
const args = message.content.slice(prefix.length + 10).trim().split(/ +/g);
const option = args[0];
if(!option) return message.reply("Usa una opcion (enable, disable, channel, text)")
if(option == "enable"){
(async () => {
let enadis = await keyv.get('disen');
if(enadis == "enable") return message.reply("La bienvenida ya esta activada")
await keyv.set('disen', 'enable');
const embed = new Discord.RichEmbed()
.setTitle('El mensaje de bienvenida ha sido activado')
.setColor("GREEN")
message.channel.send(embed);
})();
}
else if(option == "disable"){
(async () => {
let enadis = await keyv.get('disen');
if(enadis == "disable") return message.reply("La bienvenida ya esta desactivada")
await keyv.set('disen', 'disable');
const embed = new Discord.RichEmbed()
.setTitle('El mensaje de bienvenida ha sido desactivado')
.setColor("RED")
message.channel.send(embed);
})();
}
else if(option == "channel"){
(async () => {
const optionc = args[1];
const channel = message.content.replace(/\D/g,'');
if(!channel) return message.reply("El canal <#" + optionc + "> no fue encontrado, recuerda que tienes que hacer una mencion del canal")
if(!optionc) return message.reply("Escribe el canal de bienvenidas")
await keyv.set('channel', channel);
let id = await keyv.get('channel');
const embed = new Discord.RichEmbed()
.setTitle('El canal de bienvenidas ha sido cambiado. id= ' + id)
.setColor("GREEN")
message.channel.send(embed);
client.channels.get(id).send("testing channel send" + id)
})();
}
else if(option == "text"){
(async () => {
const text = args.slice(1).join(" ");
if(!text) return message.reply("Escribe el texto de bienvenida")
await keyv.set('welcometext', text);
let ntext = await keyv.get('welcometext');
const embed = new Discord.RichEmbed()
.setTitle('El texto de bienvenida ahora es ' + text)
.setColor("GREEN")
message.channel.send(embed);
})();
}
这是用户输入时激活的功能
client.on("guildMemberAdd", (member) => {
(async () => {
let ced = await keyv.get('disen');
let id = await keyv.get('channel');
let text = await keyv.get('welcometext');
if(ced == "disable") return;
console.log(`Nuevo usuario: ${member.user.username} se ha unido a ${member.guild.name}.`);
client.channels.get(id).send("testing channel send" + id)
})();
});
}
我证明“ keyv”正在保存设置,如果保存的话。 但是当有人加入服务器时,它会向我显示此错误
(node:6277) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send messages to this user
at item.request.gen.end (/rbd/pnpm-volume/37a20212-2fd5-4d84-8209-0cb6ac43bf5d/node_modules/.registry.npmjs.org/discord.js/11.5.1/node_modules/discord.js/src/client/rest/RequestHandlers/Sequential.js:85:15)
at then (/rbd/pnpm-volume/37a20212-2fd5-4d84-8209-0cb6ac43bf5d/node_modules/.registry.npmjs.org/discord.js/11.5.1/node_modules/discord.js/node_modules/snekfetch/src/index.js:215:21)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:6277) 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: 2)
(node:6277) [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.
Nuevo usuario: User se ha unido a server.
(node:6277) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of undefined
at /app/server.js:61:32
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:6277) 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: 3)