Мне надо чтобы тикет в дискорде открывался с таким названием у человека - "ticket-NickName".
Как это сделать?
Код который надо изменить:
const { createWriteStream } = require('fs');
const { MessageEmbed, MessageSelectMenu, MessageActionRow, MessageButton } = require('discord.js');
module.exports = async (client, int) => {
const req = int.customId.split('_')[0];
client.emit('ticketsLogs', req, int.guild, int.member.user);
switch (req) {
case 'createTicket': {
const selectMenu = new MessageSelectMenu();
selectMenu.setCustomId('newTicket');
selectMenu.setPlaceholder('Choose a reason for the ticket');
selectMenu.addOptions([
{
emoji: '',
label: 'Consultant',
description: 'Talking with the | Consultant',
value: 'newTicket_Support'
},
{
emoji: '',
label: 'Moderation',
description: 'Talking with the | Gérant',
value: 'newTicket_Moderation'
},
]);
const row = new MessageActionRow().addComponents(selectMenu);
return int.reply({ content: 'What will be the reason for the ticket ?', components: [row], ephemeral: true });
}
case 'newTicket': {
const reason = int.values[0].split('_')[1];
const channel = int.guild.channels.cache.find(x => x.name === `ticket-${int.member.id}`);
if (!channel) {
await int.guild.channels.create(`ticket-${int.member.id}`, {
type: 'GUILD_TEXT',
topic: `Ticket created by ${int.member.user.username}${reason ? ` (${reason})` : ''} ${new Date(Date.now()).toLocaleString()}`,
permissionOverwrites: [
{
id: int.guild.id,
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES']
},
{
id: int.member.id,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES']
},
{
id: client.user.id,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES']
}
]
});
const channel = int.guild.channels.cache.find(x => x.name === `ticket-${int.member.id}`);
const ticketEmbed = new MessageEmbed();
ticketEmbed.setColor('GREEN');
ticketEmbed.setAuthor(`Your ticket has been successfully created ${int.member.user.username}${reason ? ` (${reason})` : ''} ✅`);
ticketEmbed.setDescription('*To close the current ticket click on the reaction below, warning it is impossible to go back !*');
const closeButton = new MessageButton();
closeButton.setStyle('DANGER');
closeButton.setLabel('Close this ticket');
closeButton.setCustomId(`closeTicket_${int.member.id}`);
const row = new MessageActionRow().addComponents(closeButton);
await channel.send({ embeds: [ticketEmbed], components: [row] });
return int.update({ content: `Your ticket is open <@${int.member.id}> <#${channel.id}> ✅`, components: [], ephemeral: true });
} else {
return int.update({ content: `You already have an open ticket <#${channel.id}> ❌`, components: [], ephemeral: true });
}
}
case 'closeTicket': {
const channel = int.guild.channels.cache.get(int.channelId);
await channel.edit({
permissionOverwrites: [
{
id: int.guild.id,
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES']
},
{
id: int.customId.split('_')[1],
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES']
},
{
id: client.user.id,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES']
}
]
});
const ticketEmbed = new MessageEmbed();
ticketEmbed.setColor('RED');
ticketEmbed.setAuthor(`${int.member.user.username} has decided to close this ticket ❌`);
ticketEmbed.setDescription('*To permanently delete the ticket or to reopen the ticket click on the button below.*');
const reopenButton = new MessageButton();
reopenButton.setStyle('SUCCESS');
reopenButton.setLabel('Reopen this ticket');
reopenButton.setCustomId(`reopenTicket_${int.customId.split('_')[1]}`);
const saveButton = new MessageButton();
saveButton.setStyle('SUCCESS');
saveButton.setLabel('✅Save this ticket');
saveButton.setCustomId(`saveTicket_${int.customId.split('_')[1]}`);
const deleteButton = new MessageButton();
deleteButton.setStyle('DANGER');
deleteButton.setLabel('⚠️Delete this ticket');
deleteButton.setCustomId('deleteTicket');
const row = new MessageActionRow().addComponents(reopenButton, saveButton, deleteButton);
return int.reply({ embeds: [ticketEmbed], components: [row] });
}
case 'reopenTicket': {
const channel = int.guild.channels.cache.get(int.channelId);
await channel.edit({
permissionOverwrites: [
{
id: int.guild.id,
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES']
},
{
id: int.customId.split('_')[1],
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES']
},
{
id: client.user.id,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES']
}
]
});
const ticketEmbed = new MessageEmbed();
ticketEmbed.setColor('GREEN');
ticketEmbed.setAuthor(`The ticket has been reopened ✅`);
ticketEmbed.setDescription('*To close the current ticket click on the reaction below, warning it is impossible to go back !*');
const closeButton = new MessageButton();
closeButton.setStyle('DANGER');
closeButton.setLabel('❌Close this ticket');
closeButton.setCustomId(`closeTicket_${int.customId.split('_')[1]}`);
const row = new MessageActionRow().addComponents(closeButton);
return int.reply({ embeds: [ticketEmbed], components: [row] });
}
case 'deleteTicket': {
const channel = int.guild.channels.cache.get(int.channelId);
return channel.delete();
}
case 'saveTicket': {
const channel = int.guild.channels.cache.get(int.channelId);
await channel.messages.fetch().then(async msg => {
let messages = msg.filter(msg => msg.author.bot !== true).map(m => {
const date = new Date(m.createdTimestamp).toLocaleString();
const user = `${m.author.tag}${m.author.id === int.customId.split('_')[1] ? ' (ticket creator)' : ''}`;
return `${date} - ${user} : ${m.attachments.size > 0 ? m.attachments.first().proxyURL : m.content}`;
}).reverse().join('\n');
if (messages.length < 1) messages = 'There are no messages in this ticket... strange';
const ticketID = Date.now();
const stream = await createWriteStream(`./data/${ticketID}.txt`);
stream.once('open', () => {
stream.write(`User ticket ${int.customId.split('_')[1]} (channel #${channel.name})\n\n`);
stream.write(`${messages}\n\nLogs ${new Date(ticketID).toLocaleString()}`);
stream.end();
});
stream.on('finish', () => int.reply({ files: [`./data/${ticketID}.txt`] }));
});
}
}
};