This is my code:
const { EmbedBuilder, SlashCommandBuilder, ActionRowBuilder, ModalBuilder, ButtonBuilder, InteractionCollector } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('ticket')
.setDescription('Create a support ticket.')
.setDefaultPermission(true),
async execute(interaction) {
const embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle('Support Ticket')
.setDescription('Please select the type of ticket you want to create.')
.addFields(
{ name: 'Report a Member', value: 'Click this button if you want to report a member.' },
{ name: 'Q&A', value: 'Click this button if you have a question.' },
{ name: 'Report a Problem', value: 'Click this button if you want to report a problem.' },
{ name: 'Other', value: 'Click this button if your issue does not fit into any of the above categories.' },
);
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setLabel('Report a Member')
.setCustomId('report_member')
.setStyle('Primary'),
new ButtonBuilder()
.setLabel('Q&A')
.setCustomId('qa')
.setStyle('Primary'),
new ButtonBuilder()
.setLabel('Report a Problem')
.setCustomId('report_problem')
.setStyle('Primary'),
new ButtonBuilder()
.setLabel('Other')
.setCustomId('other')
.setStyle('Primary'),
);
await interaction.reply({ content: 'Please select the type of ticket you want to create.', embeds: [embed], components: [row] });
const collector = new InteractionCollector(interaction.client, { filter: (i) => i.user.id === interaction.user.id, time: 60000 });
collector.on('collect', async (i) => {
switch (i.customId) {
case 'report_member':
await createTicketModal(i, 'Report a Member');
break;
case 'qa':
await createTicketModal(i, 'Q&A');
break;
case 'report_problem':
await createTicketModal(i, 'Report a Problem');
break;
case 'other':
await createTicketModal(i, 'Other');
break;
}
});
collector.on('end', async (collected) => {
if (collected.size === 0) {
await interaction.editReply({ content: 'You did not select a ticket type in time. Please try again.', embeds: [], components: [] });
}
});
async function createTicketModal(i, ticketType) {
const modal = new ModalBuilder()
.setTitle(`${ticketType} Ticket`)
.setDescription('Please describe your problem.')
.addInput('description', 'string', { label: 'Problem Description' })
.build();
await i.update({ content: 'Please describe your problem.', components: [], embeds: [modal.embed] });
const modalCollector = new InteractionCollector(i.client, { filter: (interaction) => interaction.user.id === i.user.id, time: 60000 });
modalCollector.on('collect', async (interaction) => {
if (interaction.isMessageComponent()) {
const description = interaction.values[0];
await interaction.deferUpdate();
const channel = await interaction.guild.channels.create(`${i.user.username}-ticket`, {
type: 'text',
parent: 'PUT_YOUR_CATEGORY_ID_HERE', // Replace with the ID of the category you want to create the ticket channel in
permissionOverwrites: [
{
id: interaction.guild.id,
deny: 'VIEW_CHANNEL',
},
{
id: i.user.id,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'ATTACH_FILES'],
},
],
});
if (!channel.isText()) {
await interaction.followUp({ content: `Failed to create a text channel for your ${ticketType} ticket.`, embeds: [], components: [] });
return;
}
const embed = new EmbedBuilder()
.setTitle(`${ticketType} Ticket`)
.setDescription(`Problem Description: ${description}`)
.setColor('#0099ff')
.build();
await channel.send(`${i.user}`, { embeds: [embed] });
await interaction.followUp({ content: `Your ${ticketType} ticket has been created: <#${channel.id}>`, embeds: [], components: [] });
}
});
modalCollector.on('end', async (collected) => {
if (collected.size === 0) {
await i.update({ content: 'You did not describe your problem in time. Please try again.', components: [], embeds: [] });
}
});
}
}
}
Here's the problem, I'm trying to create a ticket command (/ticket
) that will send an Embed Message in a channel with 4 buttons. When you click one of the buttons a modal must pop-up with the question 'Please describe your problem.' then create a new channel and send a message in the channel created with the answer the user gave at the modal in an Embed Message. In the process, it sends the Embed Message but crashes when I click the buttons. In the console/prompt it send this error:
C:\---\---\---\---\node_modules\discord.js\src\client\actions\InteractionCreate.js:50
if (channel && !channel.isTextBased()) return;
^
TypeError: channel.isTextBased is not a function
NOTE: This is not a copy of this article! That answer there cannot fix my problem! Also, if is there any other problem or crash that might appear later I would be very pleased if you could resolve it too. Thanks! Any answer is appreciated!