【问题标题】:start-giveaway... `start` is undefinedstart-giveaway ... `start` 未定义
【发布时间】:2021-01-06 10:52:50
【问题描述】:

我有一个赠品命令,它说当我执行命令时 start 是未定义的。 我的代码:

const ms = require('ms');

exports.run = async (client, message, args) => {

    // If the member doesn't have enough permissions
    if(!message.member.hasPermission('MANAGE_MESSAGES') && !message.member.roles.cache.some((r) => r.name === "Giveaways")){
        return message.channel.send(':x: You need to have the manage messages permissions to start giveaways.');
    }

    // Giveaway channel
    let giveawayChannel = message.mentions.channels.first();
    // If no channel is mentionned
    if(!giveawayChannel){
        return message.channel.send(':x: You have to mention a valid channel!');
    }

    // Giveaway duration
    let giveawayDuration = args[1];
    // If the duration isn't valid
    if(!giveawayDuration || isNaN(ms(giveawayDuration))){
        return message.channel.send(':x: You have to specify a valid duration!');
    }

    // Number of winners
    let giveawayNumberWinners = args[2];
    // If the specified number of winners is not a number
    if(isNaN(giveawayNumberWinners) || (parseInt(giveawayNumberWinners) <= 0)){
        return message.channel.send(':x: You have to specify a valid number of winners!');
    }

    // Giveaway prize
    let giveawayPrize = args.slice(3).join(' ');
    // If no prize is specified
    if(!giveawayPrize){
        return message.channel.send(':x: You have to specify a valid prize!');
    }

    // Start the giveaway
    client.giveawaysManager.start(giveawayChannel, {
        // The giveaway duration
        time: ms(giveawayDuration),
        // The giveaway prize
        prize: giveawayPrize,
        // The giveaway winner count
        winnerCount: giveawayNumberWinners,
        // Who hosts this giveaway
        hostedBy: client.config.hostedBy ? message.author : null,
        // Messages
        messages: {
            giveaway: (client.config.everyoneMention ? "@everyone\n\n" : "")+"???????? **GIVEAWAY** ????????",
            giveawayEnded: (client.config.everyoneMention ? "@everyone\n\n" : "")+"???????? **GIVEAWAY ENDED** ????????",
            timeRemaining: "Time remaining: **{duration}**!",
            inviteToParticipate: "React with ???? to participate!",
            winMessage: "Congratulations, {winners}! You won **{prize}**!",
            embedFooter: "Giveaways",
            noWinner: "Giveaway cancelled, no valid participations.",
            hostedBy: "Hosted by: {user}",
            winners: "winner(s)",
            endedAt: "Ended at",
            units: {
                seconds: "seconds",
                minutes: "minutes",
                hours: "hours",
                days: "days",
                pluralS: false // Not needed, because units end with a S so it will automatically removed if the unit value is lower than 2
            }
        }
    });

    message.channel.send(`Giveaway started in ${giveawayChannel}!`);

};
exports.conf = {
    enabled: true,
    guildOnly: true,
    aliases: ["defaults"],
    permLevel: "modarater"
  };
  
  exports.help = {
    name: "start-giveaway",
    category: "misc",
    description: "well start the giveaway.",
    usage: "~start-giveaway   (may not work)"
  };

控制台中的错误: TypeError:无法读取未定义的属性“开始” 在 Object.exports.run (C:\Users\Tanner Terrio\Desktop\FBP\guidebot\commands\start-giveaway.js:39:29) 在 module.exports (C:\Users\Tanner Terrio\Desktop\FBP\guidebot\events\message.js:69:7) 在 Client.emit (events.js:314:20) 在 MessageCreateAction.handle (C:\Users\Tanner Terrio\Desktop\FBP\guidebot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14) 在 Object.module.exports [as MESSAGE_CREATE] (C:\Users\Tanner Terrio\Desktop\FBP\guidebot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32) 在 WebSocketManager.handlePacket (C:\Users\Tanner Terrio\Desktop\FBP\guidebot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31) 在 WebSocketShard.onPacket (C:\Users\Tanner Terrio\Desktop\FBP\guidebot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22) 在 WebSocketShard.onMessage (C:\Users\Tanner Terrio\Desktop\FBP\guidebot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10) 在 WebSocket.onMessage (C:\Users\Tanner Terrio\Desktop\FBP\guidebot\node_modules\ws\lib\event-target.js:125:16) 在 WebSocket.emit (events.js:314:20)>

【问题讨论】:

  • 似乎client.giveawaysManager 的某些内容无法正常工作。您应该调查一下,因为它说它找不到任何属于 client.giveawaysManager 的孩子的东西,因为它不存在。

标签: javascript discord.js


【解决方案1】:

也许您可以尝试将 start-giveaway 重命名为 startGiveaway。因为 Javascript 不允许在函数或变量名中使用 '-' 字符。

【讨论】:

    猜你喜欢
    • 2018-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-11
    • 2018-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多