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

时间:2020-05-16 16:30:10

标签: javascript function bots discord.js

因此,我正在使用“ discord-giveaways”软件包,并且我想使用“ exemptMembers”选项,该选项是一项功能,通过它可以设置不允许谁参加赠品的活动,我希望那些还没有加入特定的服务器不能参加,但是我不确定编码是否正确,并且还有错误:CH3我真的不知道要解决,所以如果有人可以说会很好我我做错了。

TypeError: Cannot read property 'members' of undefined

如果函数返回true,则该成员不应参与赠品:var server = require('./commands/giveaway/start-giveaway.js') let guild = client.guilds.cache.get(server) // Init discord giveaways const { 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() } });

如果我完全做错了Please,请不要用力烘烤我。

“启动赠予”文件:

exemptMembers: !guild.members.fetch()

1 个答案:

答案 0 :(得分:1)

问题在于,<tensorflow.python.keras.layers.wrappers.Bidirectional at 0x7f89a9f2fb00> 文件在您提供的第一个代码示例中需要时不会返回任何服务器ID。因此start-giveaway.js将永远是let guild = client.guilds.cache.get(server)

通过查看discord-giveaways documentation,您可以发现在开始赠品的选项中,您可以再次定义undefined属性,因此您应该这样做:

首先,从GiveawaysManager中删除exemptMembers属性。 然后,如下所示修改exemptMembers文件。

警告-20年5月19日

start-giveaway.js属性目前可能无法正常工作,目前issue中已打开discord-giveaway GitHub

exemptMembers

像这样,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时定义。