Discord JS,我的用户在对表情符号做出反应时能够创建无限的票务渠道
Discord JS, my users are able to create unlimited ticket channels when they react to the emoji
当用户对这个表情符号做出反应时,他们可以创建无限的票证通道,我在我的脚本中遗漏了哪一部分,以便用户只能创建一张票证,直到他们再次关闭它?
我的机器人 ID 是:701327880046510080
如有任何帮助,我们将不胜感激! :)
bot.on('messageReactionAdd', async (reaction, user, channel) => {
if(user.partial) await user.fetch();
if(reaction.partial) await reaction.fetch();
if(reaction.message.partial) await reaction.message.fetch();
if(user.bot) return;
let ticketid = await settings.get(`${reaction.message.guild.id}-ticket`);
if(!ticketid) return;
if(reaction.message.id == ticketid && reaction.emoji.name == '') {
reaction.users.remove(user);
const ticketChannel = reaction.message.guild.channels.cache.find(chan => chan.name === `ticket-${user.username}`)
if (ticketChannel) return;
reaction.message.guild.channels.create(`ticket-${user.username}`, {
parent: '701254271861260389',
position: 1,
permissionOverwrites: [
{
id: '701327880046510080',
allow: ["MANAGE_CHANNELS", "MANAGE_GUILD", "MANAGE_ROLES", "MANAGE_EMOJIS", "READ_MESSAGE_HISTORY", "MANAGE_MESSAGES", "SEND_MESSAGES", "VIEW_CHANNEL"]
},
{
id: user.id,
allow: ["SEND_MESSAGES", "VIEW_CHANNEL", "READ_MESSAGE_HISTORY"]
},
{
id: reaction.message.guild.roles.everyone,
deny: ["VIEW_CHANNEL"]
},
{
id: '306893721725829121',
allow: ["SEND_MESSAGES", "VIEW_CHANNEL", "READ_MESSAGE_HISTORY"]
}
],
type: 'text'
}).then(async channel => {
EMBED STUFF ..irrelevant. <-ignore this
send.react("")
})
}
if(reaction.emoji.name == ''){
if(!reaction.message.channel.name.includes("ticket-")) return;
reaction.users.remove(user);
reaction.message.channel.delete()
}
})
将这些行添加到您的代码中
bot.on('messageReactionAdd', async (reaction, user, channel) => {
if(user.partial) await user.fetch();
if(reaction.partial) await reaction.fetch();
if(reaction.message.partial) await reaction.message.fetch();
if(user.bot) return;
let ticketid = await settings.get(`${reaction.message.guild.id}-ticket`);
if(!ticketid) return;
// add below here
const existing = bot.channels.cache.find(c => c.name === `ticket-${user.username}`)
if (existing) {
return reaction.message.reply({
content: `You already have a ticket open, please close it first before creating a new one. See the ${existing} channel`
});
}
// add above here
// rest of code
当用户对这个表情符号做出反应时,他们可以创建无限的票证通道,我在我的脚本中遗漏了哪一部分,以便用户只能创建一张票证,直到他们再次关闭它?
我的机器人 ID 是:701327880046510080
如有任何帮助,我们将不胜感激! :)
bot.on('messageReactionAdd', async (reaction, user, channel) => {
if(user.partial) await user.fetch();
if(reaction.partial) await reaction.fetch();
if(reaction.message.partial) await reaction.message.fetch();
if(user.bot) return;
let ticketid = await settings.get(`${reaction.message.guild.id}-ticket`);
if(!ticketid) return;
if(reaction.message.id == ticketid && reaction.emoji.name == '') {
reaction.users.remove(user);
const ticketChannel = reaction.message.guild.channels.cache.find(chan => chan.name === `ticket-${user.username}`)
if (ticketChannel) return;
reaction.message.guild.channels.create(`ticket-${user.username}`, {
parent: '701254271861260389',
position: 1,
permissionOverwrites: [
{
id: '701327880046510080',
allow: ["MANAGE_CHANNELS", "MANAGE_GUILD", "MANAGE_ROLES", "MANAGE_EMOJIS", "READ_MESSAGE_HISTORY", "MANAGE_MESSAGES", "SEND_MESSAGES", "VIEW_CHANNEL"]
},
{
id: user.id,
allow: ["SEND_MESSAGES", "VIEW_CHANNEL", "READ_MESSAGE_HISTORY"]
},
{
id: reaction.message.guild.roles.everyone,
deny: ["VIEW_CHANNEL"]
},
{
id: '306893721725829121',
allow: ["SEND_MESSAGES", "VIEW_CHANNEL", "READ_MESSAGE_HISTORY"]
}
],
type: 'text'
}).then(async channel => {
EMBED STUFF ..irrelevant. <-ignore this
send.react("")
})
}
if(reaction.emoji.name == ''){
if(!reaction.message.channel.name.includes("ticket-")) return;
reaction.users.remove(user);
reaction.message.channel.delete()
}
})
将这些行添加到您的代码中
bot.on('messageReactionAdd', async (reaction, user, channel) => {
if(user.partial) await user.fetch();
if(reaction.partial) await reaction.fetch();
if(reaction.message.partial) await reaction.message.fetch();
if(user.bot) return;
let ticketid = await settings.get(`${reaction.message.guild.id}-ticket`);
if(!ticketid) return;
// add below here
const existing = bot.channels.cache.find(c => c.name === `ticket-${user.username}`)
if (existing) {
return reaction.message.reply({
content: `You already have a ticket open, please close it first before creating a new one. See the ${existing} channel`
});
}
// add above here
// rest of code