1 回答
TA贡献1845条经验 获得超8个赞
问题是,当您在第一个代码示例中需要它时,文件将不会返回任何服务器 ID。所以将永远是.start-giveaway.js
let guild = client.guilds.cache.get(server)
undefined
通过查看不和谐赠品文档,您可以发现在开始赠品的选项中,您可以再次定义属性,因此这是您应该做的:exemptMembers
首先,从赠品管理器中删除该属性。然后,修改如下文件。exemptMembers
start-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
添加回答
举报