(节点:44564)未处理的PromiseRejectionWarning:TypeError:client.on不是函



我目前正在制作一个带有大量不同命令的discord bot,并在实现了一个?乞求和a?bal命令我乞求我想象中的货币"比特",这似乎破坏了很多代码。除了一个打字错误外,我什么都能修?验证你什么时候打字?验证机器人是否向您发送的聊天发送嵌入?在中验证,并要求成员对嵌入做出反应,并打勾以指定"成员"角色。打字时?验证并按下回车键,嵌入就会出现,机器人也会用勾号对自己做出反应,尽管在做出反应时,成员不会获得角色。当我查看终端时,出现了这个错误,

(node:44564) UnhandledPromiseRejectionWarning: TypeError: client.on is not a function
at Object.execute (C:Users13933DesktopVixecommandsverify.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);
}
};

这是一个简单的修复方法,只需找到以下行:

async execute(message, client, args, Discord)

并将其更改为

async execute(message, args, cmd, client, Discord, profileData)

问题是在command.execute(message, args, cmd, client, Discord, profileData);消息.js

执行参数,其中";message、args、cmd、client、Discord、profileData";但是在您的verfiy文件中;消息,客户端,args,Discord";您没有添加";args,cmd";在客户端之前,因此客户端被定义为错误的

另一件事可能会在将来打乱你的代码!把这条线const { MessageEmbed } = require('discord.js');放在最上面。。

最新更新