所以我做了一个赠品命令,让用户选择服务器、角色和作为要求发送的新消息,一切正常,直到选择服务器要求,当你输入服务器 ID 时,什么也没有发生,并且它不编辑消息,我尝试这样做,以便您需要放置邀请而不是服务器 id,但希望它是服务器 id。如果您不发送任何要求,它会跳过服务器要求,但是如果您在角色要求上选择不发送,它会出现错误并停留在那里并且没有任何反应。目前真的不知道如何解决这个问题。 这是赠品命令的代码。
const ms = require("ms");
const Discord = require('discord.js')
module.exports.run = async (client, message, settings) => {
let time = "";
let winners = parseFloat();
let prize = "";
let embed = new Discord.MessageEmbed()
.setTitle("Create A Giveaway!")
.setColor("#406da2")
.setFooter(client.user.username, client.user.displayAvatarURL())
.setTimestamp();
const msg = await message.channel.send(
embed.setDescription(
"In which channel would you like the giveaway to start in?\nPlease tag the channel or provide it's ID.\n **Must Reply within 30 seconds!**"
)
)
let xembed = new Discord.MessageEmbed()
.setTitle("Sorry! Looks Like We Met A Timeout! ?")
.setColor("#FF0000")
.setDescription('?You took too much time to decide!\nUse ',`\`${settings.prefix}gstart\``,' again to start a new giveaway!\nTry to respond within **30 seconds** this time!')
.setFooter(client.user.username, client.user.displayAvatarURL())
.setTimestamp()
const filter = m => m.author.id === message.author.id && !m.author.bot
collector4.on("collect", async collect4 => {
const response4 = collect4.content.toLowerCase();
prize = response4;
await collect4.delete()
collector4.stop(
msg.edit(
embed.setDescription(
"Alright! Next, Do you want to have a server joining requirement for the giveaway?\n**Must Reply within 30 seconds!**\n\n**Bot Must Be In The Server!**\nRespond with `none` If no requirements!"
)
)
);
const collector5 = await message.channel.createMessageCollector(
filter,
{ max: 3, time: 30000 }
);
collector5.on("collect", async collect5 => {
const response5 = collect5.content;
await collect5.delete()
let server = await client.guilds.cache.get(response5);
if (response5.toLowerCase() !== "none") {
if (!server) {
return msg.edit(
embed.setDescription(
`Sorry! **It seems like I couldn't get the server id** probably because im not in that server, ask the owner to invite me there to set that as a requirement`
)
)
} else {
let invite = await (server.channels.cache.filter(c => c.type === 'text').find(x => x.position == 0)).createInvite(
{
maxAge: 0
},
`Giveaway command ran by: ${message.author.tag}`
)
settings.requirements.push(`Join Server: [${server.name}](${invite})`);
};
} else {
collector5.stop(
msg.edit(
embed.setDescription(
"Alright! Next, Do you want to have a role requirement for the giveaway?\n**Must Reply within 30 seconds!**\nRespond with `none` If no requirements!"
)
)
);
}
const collector6 = await message.channel.createMessageCollector(
filter,
{ max: 1, time: 30000 }
);
collector6.on("collect", async collect6 => {
const response6 = collect6.content;
await collect6.delete()
if (response6.toLowerCase() !== "none") {
let role = message.guild.roles.cache.get(response6);
if (!role) {
return msg.edit(
embed.setDescription('Sorry! Seems like I Couldn\'t get the role or the role id')
)
} else {
requirements.push(`Must have role: <@&${role.id}>`);
collector6.stop(
msg.edit(
embed.setDescription(`Okay almost done, Do you want them to have messages sent requirements\n**Must Reply within 30 seconds!**\nRespond with \`none\` If no requirements!`)
)
)
}
};
const collector7 = await message.channel.createMessageCollector(
filter,
{ max: 1, time: 30000 }
);
collector7.on("collect", async collect7 => {
const response7 = collect7.content;
await collect7.delete()
if (response7.toLowerCase() !== "none") {
let messagecount = parseFloat(response7);
if (isNaN(messagecount)) {
return msg.edit(
embed.setDescription('you must select a valid number or \`none\`')
)
} else {
if (messagecount < 1 || messagecount > 1000) {
return msg.edit(
embed.setDescription('the message requirement Can\'t be less than 1 or greater than 1000 messages.')
)
} else {
collector7.stop(
msg.edit(
embed.setDescription(
`Alright! Giveaway has been started in ${channel} for **${prize}** which will last for **${ms(
time,
{ long: true }
)}** and there will be **${winnersCount}** winner(s)! and users would have to join ${response5}`
)
)
)
msgcounttest = msggiveaways.length; // don't do +1 because it's .length
msgdatabase.push([]);
msggiveaways.push({id:message.guild.id,count:messagecount});
requirements.push(`Send ${messagecount} new messages.`);
};
};
} else {
msgcounttest = null;
};
let thing = msgcounttest;
message.delete();
let giveawayembed = new Discord.MessageEmbed()
.setTitle('Giveaway! ' + prize)
.setColor("YELLOW")
.setDescription(`React ? to join the giveaway.`)
.addField("Winners", "There will be **" + parseInt(winnersCount) + "** winners.")
.addField("Requirements", (await requirements).length == 0 ? "None!" : requirements.join("\n") + (!prize ? "" : "\n" + prize.join(" | ").slice(prize[0].length + 3)))
.setFooter("Ends after " + ms(parseInt(time), {long:true}))
channel.send(giveawayembed).then(msg => {
msg.react("?");
let filter = async (reaction, user) => {
if (user.id !== client.user.id) {
if (reaction.emoji.name == "?") {
let userreacts = msg.reactions.cache.filter(reaction => reaction.users.cache.has(user.id));
if (response5.toLowerCase() !== "none") {
let server = await client.guilds.cache.get(response5);
if (server) {
if (server.members.cache.filter(u => u.id == user.id).array().length == 0) {
for (let reaction of userreacts.values()) {
await reaction.users.remove(user.id);
}
}
}
}
if (response7.toLowerCase() !== "none") {
let messagecount = parseFloat(response7);
if (msgdatabase[thing].length == 0) {
for (let reaction of userreacts.values()) {
await reaction.users.remove(user.id);
}
} else {
for (var i = 0, len = msgdatabase[thing].length; i < len; i++) {
if (msgdatabase[thing][i].id == message.author.id) {
let test = msgdatabase[thing][i];
if (test.id == user.id) {
if (test.count < messagecount) {
for (let reaction of userreacts.values()) {
await reaction.users.remove(user.id);
}
}
}
}
}
}
}
if (response6.toLowerCase() !== "none") {
let role = message.guild.roles.cache.get(response6);
if (role) {
if (!message.guild.members.cache.get(user.id).roles.cache.has(role.id)) {
for (let reaction of userreacts.values()) {
await reaction.users.remove(user.id);
}
}
}
}
};
};
};