8m3ta
DIAdiscord.js - Imagine an app
•Created by 8m3ta on 2/21/2025 in #djs-questions
Failure to create channel
For some reason, I tried a lot of ways to create a channel when they click the button but it doesn't work every time.
const { Events, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelType, PermissionsBitField } = require('discord.js');
module.exports = {
name: Events.InteractionCreate,
async execute(interaction) {
if (interaction.isCommand()) {
if (interaction.commandName === 'ordersend') {
const embed = new EmbedBuilder()
.setColor('#e6072c')
.setTitle('Order Menu')
.setDescription('Click the button to open a ticket for your order!');
const row = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId('open_ticket')
.setLabel('Open Ticket')
.setStyle(ButtonStyle.Primary)
);
await interaction.reply({
embeds: [embed],
components: [row],
});
}
}
if (interaction.isButton()) {
console.log(`Button clicked: ${interaction.customId}`); // Debugging log
if (interaction.customId === 'open_ticket') {
try {
const botMember = await interaction.guild.members.fetch(interaction.client.user.id);
if (!botMember.permissions.has(PermissionsBitField.Flags.ManageChannels)) {
return await interaction.reply({
content: 'I do not have permission to create channels!',
ephemeral: true,
});
}
const channel = await interaction.guild.channels.create({
name: `ticket-${interaction.user.username}`,
type: ChannelType.GuildText,
topic: `Ticket opened by ${interaction.user.username}`,
permissionOverwrites: [
{
id: interaction.guild.id,
deny: [PermissionsBitField.Flags.ViewChannel],
},
{
id: interaction.user.id,
allow: [PermissionsBitField.Flags.ViewChannel],
},
],
});
const ticketEmbed = new EmbedBuilder()
.setColor('#00FF00')
.setTitle('Ticket Opened')
.setDescription(`Hello ${interaction.user.username}, your support ticket is now open!`);
await channel.send({ embeds: [ticketEmbed] });
await interaction.reply({
content: `Your ticket has been opened: ${channel}`,
ephemeral: true,
});
} catch (error) {
console.error('Error while creating ticket channel:', error);
await interaction.reply({
content: 'There was an error creating your ticket. Please try again later.',
ephemeral: true,
});
}
}
}
},
};
const { Events, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelType, PermissionsBitField } = require('discord.js');
module.exports = {
name: Events.InteractionCreate,
async execute(interaction) {
if (interaction.isCommand()) {
if (interaction.commandName === 'ordersend') {
const embed = new EmbedBuilder()
.setColor('#e6072c')
.setTitle('Order Menu')
.setDescription('Click the button to open a ticket for your order!');
const row = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId('open_ticket')
.setLabel('Open Ticket')
.setStyle(ButtonStyle.Primary)
);
await interaction.reply({
embeds: [embed],
components: [row],
});
}
}
if (interaction.isButton()) {
console.log(`Button clicked: ${interaction.customId}`); // Debugging log
if (interaction.customId === 'open_ticket') {
try {
const botMember = await interaction.guild.members.fetch(interaction.client.user.id);
if (!botMember.permissions.has(PermissionsBitField.Flags.ManageChannels)) {
return await interaction.reply({
content: 'I do not have permission to create channels!',
ephemeral: true,
});
}
const channel = await interaction.guild.channels.create({
name: `ticket-${interaction.user.username}`,
type: ChannelType.GuildText,
topic: `Ticket opened by ${interaction.user.username}`,
permissionOverwrites: [
{
id: interaction.guild.id,
deny: [PermissionsBitField.Flags.ViewChannel],
},
{
id: interaction.user.id,
allow: [PermissionsBitField.Flags.ViewChannel],
},
],
});
const ticketEmbed = new EmbedBuilder()
.setColor('#00FF00')
.setTitle('Ticket Opened')
.setDescription(`Hello ${interaction.user.username}, your support ticket is now open!`);
await channel.send({ embeds: [ticketEmbed] });
await interaction.reply({
content: `Your ticket has been opened: ${channel}`,
ephemeral: true,
});
} catch (error) {
console.error('Error while creating ticket channel:', error);
await interaction.reply({
content: 'There was an error creating your ticket. Please try again later.',
ephemeral: true,
});
}
}
}
},
};
27 replies
DIAdiscord.js - Imagine an app
•Created by 8m3ta on 6/26/2024 in #djs-questions
Unknow Error with Intents.FLAGS.Guilds,
So Once I added the code for a interaction called user-bolo now there is a error.
11 replies
DIAdiscord.js - Imagine an app
•Created by 8m3ta on 5/17/2024 in #djs-questions
Somethings wrong, idk

83 replies