所以,我目前正在使用多种不同的命令制作一个不和谐的机器人,在实施了 ?beg 和 ?bal 命令来乞求我的虚构货币“比特”之后,它似乎破坏了很多代码.除了一个错误之外,我能够修复所有内容,该错误来自键入?verify。当您键入 ?verify 时,机器人会向您发送的聊天发送 ?verify 的嵌入,并要求成员对嵌入做出反应并打勾以赋予“成员”角色。输入 ?verify 并按下 enter 时,嵌入出现并且机器人也会用勾号对自己做出反应,尽管在做出反应时成员没有获得角色。当我查看终端时出现此错误,
(node:44564) UnhandledPromiseRejectionWarning: TypeError: client.on is not a function
at Object.execute (C:\Users\013933\Desktop\Vixe\commands\verify.js:20:16)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(node:44564) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:44564) [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.on 是在代码顶部定义的函数。
async execute(message, client, args, Discord) {
我已经在堆栈溢出时对其进行了搜索,但只是有人说我错误地声明了“客户端”,尽管当“正确”声明客户端时,我只是收到另一个错误,说“客户端”已被定义。
这是完整的代码,
module.exports = {
name: 'verify',
description: 'Allows members to react to a message to verify themselves.',
async execute(message, client, args, Discord) {
const channel = message.channel.id;
const memberRole = message.guild.roles.cache.find(role => role.name === 'Member');
const memberEmoji = '✅';
const { MessageEmbed } = require('discord.js');
let embed = new MessageEmbed()
.setColor('#800080')
.setTitle('Verification')
.setDescription('React to this embed with the :white_check_mark: to verify yourself and gain access to the server.\n'
+ `Removing your reaction to this embed will un-verify you.`);
let messageEmbed = await message.channel.send(embed);
messageEmbed.react(memberEmoji);
client.on('messageReactionAdd', async (reaction, user) => {
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();
if (user.bot) return;
if (!reaction.message.guild) return;
if (reaction.message.channel.id == channel) {
if (reaction.emoji.name === memberEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.add(memberRole);
}
} else {
return;
}
});
client.on('messageReactionRemove', async (reaction, user) => {
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();
if (user.bot) return;
if (!reaction.message.guild) return;
if (reaction.message.channel.id == channel) {
if (reaction.emoji.name === memberEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.remove(memberRole);
}
} else {
return;
}
});
}
}
这里是处理所有命令的 message.js,
const profileModel = require('../../models/profileSchema');
module.exports = async (Discord, client, message) => {
const prefix = '?';
if (!message.content.startsWith(prefix) || message.author.bot) return;
let profileData;
try {
profileData = await profileModel.findOne({ userID: message.author.id });
if(!profileData) {
let profile = await profileModel.create({
userID: message.author.id,
serverID: message.guild.id,
bits: 1000,
bank: 0,
});
profile.save();
}
} catch (err) {
console.log(err);
}
const args = message.content.slice(prefix.length).split(/ +/);
const cmd = args.shift().toLowerCase();
const command = client.commands.get(cmd);
try {
command.execute(message, args, cmd, client, Discord, profileData);
} catch (err) {
message.reply('There was an error executing this command.');
console.log(err);
}
};
抱歉,如果这是一个明显的问题,我似乎无法在其他任何地方找到适合我的情况的正确答案,因此将不胜感激(:
如果你想让我链接额外的代码,我很乐意:D
答案 0 :(得分:0)
这是一个简单的修复,只需找到这一行:
async execute(message, client, args, Discord)
并将其更改为
async execute(message, args, cmd, client, Discord, profileData)
问题是在 command.execute(message, args, cmd, client, Discord, profileData);
执行参数 where "message, args, cmd, client, Discord, profileData" 但是在您的验证文件中,“消息,客户端,参数,不和谐”的参数 您没有在客户端之前添加“args,cmd”,因此客户端定义错误
将来可能会弄乱您的代码的另一件事!取这条线 const { MessageEmbed } = require('discord.js');
并将其放在顶部..
如果有帮助,请勾选此项