Node.js 试图让彩票增加玩家的角色

Node.js 试图让彩票增加玩家的角色,node.js,discord,discord.js,Node.js,Discord,Discord.js,我正试图让一个彩票命令给一个球员一个角色,我不知道为什么它不工作,我一直在试图找出它,请帮助我修复它谢谢你,(顺便说一句,角色名称与大写和代码中的所有内容相同) .js文件中的代码: const Discord = require("discord.js"); const bot = new Discord.Client(); module.exports = { name: 'lottery', description: 'MAYBE YOU SHALL

我正试图让一个彩票命令给一个球员一个角色,我不知道为什么它不工作,我一直在试图找出它,请帮助我修复它谢谢你,(顺便说一句,角色名称与大写和代码中的所有内容相同)

.js文件中的代码:

const Discord = require("discord.js");
const bot = new Discord.Client();

module.exports = {
    name: 'lottery',
    description: 'MAYBE YOU SHALL WIN?!?!',
    execute(client, message, args) {
        var role = message.member.roles.cache.find(role => role.name === "Lucky Winner");
        const lottery = Math.floor(Math.random() * 1) + 1;
        if (lottery === 1)
            return message.reply(`Wow! You actually won! Great job! :white_check_mark: ` + message.member.guild.roles.add(role));
        message.reply(`Nope, sorry, you lost. ❌`);
    }
}
main.js文件中的代码:

const Discord = require("discord.js");
const bot = new Discord.Client();

module.exports = {
    name: 'lottery',
    description: 'MAYBE YOU SHALL WIN?!?!',
    execute(client, message, args) {
        var role = message.member.roles.cache.find(role => role.name === "Lucky Winner");
        const lottery = Math.floor(Math.random() * 1) + 1;
        if (lottery === 1)
            return message.reply(`Wow! You actually won! Great job! :white_check_mark: ` + message.member.guild.roles.add(role));
        message.reply(`Nope, sorry, you lost. ❌`);
    }
}
else if(command === 'lemmewin') {
    client.commands.get('lemmewin').execute(client, message, args);
}
控制台错误:

TypeError: Cannot read property 'execute' of undefined

这意味着不存在名为
lemmewin
的命令。所以在您的例子中,它应该是
client.commands.get('lotket').execute(client,message,args)
因为您在模块
name:'lotking'
中将命令名设置为lotking,而不是
lemmewin

问题似乎来自此
client.commands.get(“lemmewin”)
。它是如何生成
命令的?您忘记将模块添加到它了吗?您调用
client.commands.get('lemmewin')
,即使命令名为
lotking
。尝试
client.commands.get('lotking')
替代。OHHHHHHHHHDID更改是否有效?