1 回答

TA貢獻(xiàn)1845條經(jīng)驗(yàn) 獲得超8個(gè)贊
問題是,當(dāng)您在第一個(gè)代碼示例中需要它時(shí),文件將不會(huì)返回任何服務(wù)器 ID。所以將永遠(yuǎn)是.start-giveaway.js
let guild = client.guilds.cache.get(server)
undefined
通過查看不和諧贈(zèng)品文檔,您可以發(fā)現(xiàn)在開始贈(zèng)品的選項(xiàng)中,您可以再次定義屬性,因此這是您應(yīng)該做的:exemptMembers
首先,從贈(zèng)品管理器中刪除該屬性。然后,修改如下文件。exemptMembers
start-giveaway.js
警告 - 2020 年 5 月 19 日
豁免成員
屬性現(xiàn)在可能無法正常工作,目前在不和諧贈(zèng)品GitHub中打開了一個(gè)問題!
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}!`);
}
像這樣,只有當(dāng)作者給出服務(wù)器ID時(shí)才會(huì)定義。exemptMembers
添加回答
舉報(bào)