为了账号安全,请及时绑定邮箱和手机立即绑定

获取功能|内服务器的所有成员未定义|的特性成员包装:不和谐赠品

获取功能|内服务器的所有成员未定义|的特性成员包装:不和谐赠品

不负相思意 2022-08-18 15:49:14
所以我正在使用包“不和谐 - 赠品”,我想使用“豁免会员”选项,这是一个功能,我可以设置谁不允许参加赠品,我希望没有加入特定服务器的人不能参加,但我不确定编码是否正确,并且还有错误: 我真的不知道要修复,所以如果有人能告诉我我做错了什么就好了。TypeError: Cannot read property 'members' of undefinedvar server = require('./commands/giveaway/start-giveaway.js')let guild = client.guilds.cache.get(server)// Init discord giveawaysconst { GiveawaysManager } = require('discord-giveaways');client.giveawaysManager = new GiveawaysManager(client, {    storage: "./giveaways.json",    updateCountdownEvery: 5000,    default: {        botsCanWin: false,        embedColor: "0x0099ff",        embedColorEnd: "ff0000",        reaction: "🎉",        exemptMembers: !guild.members.fetch()    }});如果函数返回 true,则该成员不应参与赠品:exemptMembers: !guild.members.fetch()请不要把我烤得很硬,如果我完全做错了😅。
查看完整描述

1 回答

?
精慕HU

TA贡献1845条经验 获得超8个赞

问题是,当您在第一个代码示例中需要它时,文件将不会返回任何服务器 ID。所以将永远是.start-giveaway.jslet guild = client.guilds.cache.get(server)undefined

通过查看不和谐赠品文档,您可以发现在开始赠品的选项中,您可以再次定义属性,因此这是您应该做的:exemptMembers

首先,从赠品管理器中删除该属性。然后,修改如下文件。exemptMembersstart-giveaway.js

警告 - 2020 年 5 月 19 日

豁免成员属性现在可能无法正常工作,目前在不和谐赠品GitHub中打开了一个问题

run : async (message, client, args) => {

    const ms = require('ms');


    // 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)){

        return message.channel.send(':x: You have to specify a valid number of winners!');

    }


    // Giveaway prize

    let giveawayPrize = args.slice(4).join(' ');

    // If no prize is specified

    if(!giveawayPrize){

        return message.channel.send(':x: You have to specify a valid prize!');

    }


    // Options for the giveaway

    let giveawayStartOptions = {

        // The giveaway duration

        time: ms(giveawayDuration),

        // The giveaway prize

        prize: giveawayPrize,

        // The giveaway winner count

        winnerCount: giveawayNumberWinners,

        // Who hosts this giveaway

        hostedBy: true ? message.author : null,

        // Messages

        messages: {

            giveaway: "🎉🎉 **GIVEAWAY** 🎉🎉",

            giveawayEnded: "🎉🎉 **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",

                weeks: "weeks",

                months: "months",

                pluralS: false // Not needed, because units end with a S so it will automatically removed if the unit value is lower than 2

            } 

        }

    }


    // Require members to join a server if author does not say "no"

    if (args[3] !== 'no'){

        let server = args[3];

        console.log(server);


        if(!server){

            return message.channel.send(':x: You habe to specify a valid server ID or say "no"');

        } else {

            client.guilds.cache.get(server).members.fetch().then(otherServerMembers => {

                // Who will be excluded from this giveaway if members have to join a specific server

                giveawayStartOptions.exemptMembers = (member) => !otherServerMembers.has(member.id)

            })

        }

    }

    else {

        console.log('User sayed no');

    }


    // Start the giveaway

    client.giveawaysManager.start(giveawayChannel, giveawayStartOptions);

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


}

像这样,只有当作者给出服务器ID时才会定义。exemptMembers


查看完整回答
反对 回复 2022-08-18
  • 1 回答
  • 0 关注
  • 126 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信