Users are able to create unlimited ticket channels when they react on ๐ซ this emoji, what part do I miss in my script so that users are only able to create one ticket until they close it again?
My bots ID below is: 701327880046510080
Any help would be appreciated! ๐
JavaScript
โx
50
50
1
bot.on('messageReactionAdd', async (reaction, user, channel) => {
2
if(user.partial) await user.fetch();
3
if(reaction.partial) await reaction.fetch();
4
if(reaction.message.partial) await reaction.message.fetch();
5
if(user.bot) return;
6
7
let ticketid = await settings.get(`${reaction.message.guild.id}-ticket`);
8
9
if(!ticketid) return;
10
11
12
if(reaction.message.id == ticketid && reaction.emoji.name == '๐ซ') {
13
reaction.users.remove(user);
14
const ticketChannel = reaction.message.guild.channels.cache.find(chan => chan.name === `ticket-${user.username}`)
15
if (ticketChannel) return;
16
reaction.message.guild.channels.create(`ticket-${user.username}`, {
17
parent: '701254271861260389',
18
position: 1,
19
permissionOverwrites: [
20
{
21
id: '701327880046510080',
22
allow: ["MANAGE_CHANNELS", "MANAGE_GUILD", "MANAGE_ROLES", "MANAGE_EMOJIS", "READ_MESSAGE_HISTORY", "MANAGE_MESSAGES", "SEND_MESSAGES", "VIEW_CHANNEL"]
23
},
24
{
25
id: user.id,
26
allow: ["SEND_MESSAGES", "VIEW_CHANNEL", "READ_MESSAGE_HISTORY"]
27
},
28
{
29
id: reaction.message.guild.roles.everyone,
30
deny: ["VIEW_CHANNEL"]
31
},
32
{
33
id: '306893721725829121',
34
allow: ["SEND_MESSAGES", "VIEW_CHANNEL", "READ_MESSAGE_HISTORY"]
35
}
36
],
37
type: 'text'
38
}).then(async channel => {
39
EMBED STUFF ..irrelevant. <-ignore this
40
send.react("๐")
41
})
42
}
43
if(reaction.emoji.name == '๐'){
44
if(!reaction.message.channel.name.includes("ticket-")) return;
45
reaction.users.remove(user);
46
47
reaction.message.channel.delete()
48
}
49
})
50
โ
Advertisement
Answer
Add these lines to your code
JavaScript
1
22
22
1
bot.on('messageReactionAdd', async (reaction, user, channel) => {
2
if(user.partial) await user.fetch();
3
if(reaction.partial) await reaction.fetch();
4
if(reaction.message.partial) await reaction.message.fetch();
5
if(user.bot) return;
6
7
let ticketid = await settings.get(`${reaction.message.guild.id}-ticket`);
8
9
if(!ticketid) return;
10
โ
11
// add below here
12
const existing = bot.channels.cache.find(c => c.name === `ticket-${user.username}`)
13
โ
14
if (existing) {
15
return reaction.message.reply({
16
content: `You already have a ticket open, please close it first before creating a new one. See the ${existing} channel`
17
});
18
}
19
// add above here
20
โ
21
// rest of code
22
โ