How can i setup a ticket system with a parent category?

deploy-ticket.js code:
const { SlashCommandBuilder } = require('discord.js');
const { MessageActionRow, MessageSelectMenu, MessageEmbed } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('deploy-ticket')
.setDescription('Deploy a button to open a ticket channel')
.addChannelOption((option) => // Use the addChannelOption method
option.setName('parent_category')
.setDescription('The parent category of the ticket channel')
.setType('GUILD_CATEGORY')
.setRequired(false) // Optional
),

async execute(interaction) {
// Create an action row to contain the select menu
const row = new MessageActionRow().addComponents(parentCategorySelect);

// Create an embed to provide information about the ticket system
const embed = new MessageEmbed()
.setColor('#0099ff')
.setTitle('Ticket System')
.setDescription('Select a parent category from the dropdown menu and click the "Open Ticket" button to create a new support ticket.');

// Create a button that users can click to open a ticket
const ticketButton = new MessageButton()
.setCustomId('open_ticket')
.setLabel('Open Ticket')
.setStyle('PRIMARY');

// Send the embed with the select menu and button
await interaction.reply({ embeds: [embed], components: [row], files: [], components: [ticketButton] });
},
};
const { SlashCommandBuilder } = require('discord.js');
const { MessageActionRow, MessageSelectMenu, MessageEmbed } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('deploy-ticket')
.setDescription('Deploy a button to open a ticket channel')
.addChannelOption((option) => // Use the addChannelOption method
option.setName('parent_category')
.setDescription('The parent category of the ticket channel')
.setType('GUILD_CATEGORY')
.setRequired(false) // Optional
),

async execute(interaction) {
// Create an action row to contain the select menu
const row = new MessageActionRow().addComponents(parentCategorySelect);

// Create an embed to provide information about the ticket system
const embed = new MessageEmbed()
.setColor('#0099ff')
.setTitle('Ticket System')
.setDescription('Select a parent category from the dropdown menu and click the "Open Ticket" button to create a new support ticket.');

// Create a button that users can click to open a ticket
const ticketButton = new MessageButton()
.setCustomId('open_ticket')
.setLabel('Open Ticket')
.setStyle('PRIMARY');

// Send the embed with the select menu and button
await interaction.reply({ embeds: [embed], components: [row], files: [], components: [ticketButton] });
},
};
178 Replies
d.js toolkit
d.js toolkitβ€’9mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
treble/luna
treble/lunaβ€’9mo ago
that setType is incorrect
NNKtv28
NNKtv28β€’9mo ago
how should it be?
treble/luna
treble/lunaβ€’9mo ago
its addChannelTypes
d.js docs
d.js docsβ€’9mo ago
dtypes v10: ChannelType read more
treble/luna
treble/lunaβ€’9mo ago
types being specified with that enum that entire code is v13 you didnt happen to ask chatgpt did you?
NNKtv28
NNKtv28β€’9mo ago
i did T_T
treble/luna
treble/lunaβ€’9mo ago
yeah dont
NNKtv28
NNKtv28β€’9mo ago
its that obvious huh?
d.js docs
d.js docsβ€’9mo ago
guide Home: What's new read more
treble/luna
treble/lunaβ€’9mo ago
the comments + the fact that code is outdated
NNKtv28
NNKtv28β€’9mo ago
thing is that discord docs dont provide with examples on how to use it well observed
treble/luna
treble/lunaβ€’9mo ago
use what? buttons?
NNKtv28
NNKtv28β€’9mo ago
somehow i got 20 commands done with it and it works yes
d.js docs
d.js docsβ€’9mo ago
guide Message Components: Buttons read more
treble/luna
treble/lunaβ€’9mo ago
then you are using an outdated version
NNKtv28
NNKtv28β€’9mo ago
i wanna make a command called deploy-ticket wich will let me specify the this variables in this ticket model:
const Sequelize = require('sequelize');
const sequelize = require('../utils/database');

const Ticket = sequelize.define('ticket', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
},
userId: {
type: Sequelize.STRING,
allowNull: false,
},
parentId: {
type: Sequelize.STRING,
allowNull: true,
},
channelId: {
type: Sequelize.STRING,
allowNull: false,
},
status: {
type: Sequelize.STRING,
defaultValue: 'open', // or 'closed', 'resolved', etc.
},
subject: {
type: Sequelize.STRING,
allowNull: false,
},
description: {
type: Sequelize.TEXT,
allowNull: false,
},
// You can add more fields as needed, such as timestamps, assigned staff, etc.
});

module.exports = Ticket;
const Sequelize = require('sequelize');
const sequelize = require('../utils/database');

const Ticket = sequelize.define('ticket', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
},
userId: {
type: Sequelize.STRING,
allowNull: false,
},
parentId: {
type: Sequelize.STRING,
allowNull: true,
},
channelId: {
type: Sequelize.STRING,
allowNull: false,
},
status: {
type: Sequelize.STRING,
defaultValue: 'open', // or 'closed', 'resolved', etc.
},
subject: {
type: Sequelize.STRING,
allowNull: false,
},
description: {
type: Sequelize.TEXT,
allowNull: false,
},
// You can add more fields as needed, such as timestamps, assigned staff, etc.
});

module.exports = Ticket;
somehow it works perfectly πŸ˜„
treble/luna
treble/lunaβ€’9mo ago
then tag this post with the version you use which is not v14 also if you're asking how to get data from a db, #other-js-ts for that
NNKtv28
NNKtv28β€’9mo ago
i use V14 tho
No description
treble/luna
treble/lunaβ€’9mo ago
and waht does npm ls discord.js return
NNKtv28
NNKtv28β€’9mo ago
No description
treble/luna
treble/lunaβ€’9mo ago
the code above shouldnt work because its invalid anyhow whats your question
NNKtv28
NNKtv28β€’9mo ago
how do i set it up so it asks for the channel category ik how to make it ask for channel_id but not chanel category
treble/luna
treble/lunaβ€’9mo ago
use collectors and channel select menus or use a slashcommand and make it so you only can input categorychannels
NNKtv28
NNKtv28β€’9mo ago
is there any template that has an example of how its used? yeah im using slash commands
treble/luna
treble/lunaβ€’9mo ago
no the guide explains how everything works then you would need to adapt it to your use case well choose what you want because the code you showed uses both a slash command and selectmenus
NNKtv28
NNKtv28β€’9mo ago
yeah but i dont see any examples of how to use the GuildCategory
NNKtv28
NNKtv28β€’9mo ago
this is all it gives me
No description
treble/luna
treble/lunaβ€’9mo ago
its an enum you put it in the addChannelTypes and then only Categorychannels will be populated into the results
NNKtv28
NNKtv28β€’9mo ago
like this
No description
treble/luna
treble/lunaβ€’9mo ago
yes thats one part fixed the rest of your code still is v13
NNKtv28
NNKtv28β€’9mo ago
yayy
const { SlashCommandBuilder, ChannelType } = require('discord.js');
const { MessageActionRow, MessageSelectMenu, MessageEmbed } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('deploy-ticket')
.setDescription('Deploy a button to open a ticket channel')
.addChannelTypes(ChannelType.GuildCategory),

async execute(interaction) {
// Create an action row to contain the select menu
const row = new MessageActionRow().addComponents(parentCategorySelect);

// Create an embed to provide information about the ticket system
const embed = new MessageEmbed()
.setColor('#0099ff')
.setTitle('Ticket System')
.setDescription('Select a parent category from the dropdown menu and click the "Open Ticket" button to create a new support ticket.');

// Create a button that users can click to open a ticket
const ticketButton = new MessageButton()
.setCustomId('open_ticket')
.setLabel('Open Ticket')
.setStyle('PRIMARY');

// Send the embed with the select menu and button
await interaction.reply({ embeds: [embed], components: [row], files: [], components: [ticketButton] });
},
};
const { SlashCommandBuilder, ChannelType } = require('discord.js');
const { MessageActionRow, MessageSelectMenu, MessageEmbed } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('deploy-ticket')
.setDescription('Deploy a button to open a ticket channel')
.addChannelTypes(ChannelType.GuildCategory),

async execute(interaction) {
// Create an action row to contain the select menu
const row = new MessageActionRow().addComponents(parentCategorySelect);

// Create an embed to provide information about the ticket system
const embed = new MessageEmbed()
.setColor('#0099ff')
.setTitle('Ticket System')
.setDescription('Select a parent category from the dropdown menu and click the "Open Ticket" button to create a new support ticket.');

// Create a button that users can click to open a ticket
const ticketButton = new MessageButton()
.setCustomId('open_ticket')
.setLabel('Open Ticket')
.setStyle('PRIMARY');

// Send the embed with the select menu and button
await interaction.reply({ embeds: [embed], components: [row], files: [], components: [ticketButton] });
},
};
treble/luna
treble/lunaβ€’9mo ago
still not v14
d.js docs
d.js docsβ€’9mo ago
guide Additional Information: Updating from v13 to v14 read more
NNKtv28
NNKtv28β€’9mo ago
D:\Discord bots\Custom bot order\commands\Ticket\deploy-ticket.js:8
.addChannelTypes(ChannelType.GuildCategory),
^

TypeError: (intermediate value).setName(...).setDescription(...).addChannelTypes is not a function
at Object.<anonymous> (D:\Discord bots\Custom bot order\commands\Ticket\deploy-ticket.js:8:6)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Module.require (node:internal/modules/cjs/loader:1143:19)
at require (node:internal/modules/cjs/helpers:110:18)
at Object.<anonymous> (D:\Discord bots\Custom bot order\index.js:22:21)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)

Node.js v18.16.1
D:\Discord bots\Custom bot order\commands\Ticket\deploy-ticket.js:8
.addChannelTypes(ChannelType.GuildCategory),
^

TypeError: (intermediate value).setName(...).setDescription(...).addChannelTypes is not a function
at Object.<anonymous> (D:\Discord bots\Custom bot order\commands\Ticket\deploy-ticket.js:8:6)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Module.require (node:internal/modules/cjs/loader:1143:19)
at require (node:internal/modules/cjs/helpers:110:18)
at Object.<anonymous> (D:\Discord bots\Custom bot order\index.js:22:21)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)

Node.js v18.16.1
Huh, so addChannelTypes is not a function
treble/luna
treble/lunaβ€’9mo ago
oh yeah you need to add a channeloption ofc
NNKtv28
NNKtv28β€’9mo ago
like this?
No description
treble/luna
treble/lunaβ€’9mo ago
yep
NNKtv28
NNKtv28β€’9mo ago
PS D:\Discord bots\Custom bot order> node .\index.js
Loaded command 'info' from /Stats/info.js
Loaded command 'uptime' from /Stats/uptime.js
Loaded command 'ping' from /Stats/ping.js
Loaded command 'settings' from /Misc/settings.js
Loaded command 'urban' from /Misc/urban.js
Loaded command 'time' from /Misc/time.js
Loaded command 'add-income-role' from /Administration/add-income-role.js
Loaded command 'reset-database' from /Administration/reset-database.js
Loaded command 'set-welcome-channel' from /Administration/set-welcome-channel.js
Loaded command 'add-shop-item' from /Administration/add-shop-item.js
Loaded command 'add-balance' from /Administration/add-balance.js
Loaded command 'remove-shop-item' from /Administration/remove-shop-item.js
Loaded command 'shop' from /Economy/shop.js
Loaded command 'balance' from /Economy/balance.js
Loaded command 'buy' from /Economy/buy.js
Loaded command 'view-inventory' from /Economy/inventory.js
Loaded command 'withdraw' from /Economy/withdraw.js
Loaded command 'deposit' from /Economy/deposit.js
Loaded command 'deploy-ticket' from /Ticket/deploy-ticket.js
Loaded event 'ready' from /ready.js
Database >> SQLite is connecting...
Database >> SQLite is ready! (Latency: 0.64 ms)
Loaded utility 'undefined' from /database.js
Logged in as Custom bot order - Arsh#8722.
PS D:\Discord bots\Custom bot order> node .\index.js
Loaded command 'info' from /Stats/info.js
Loaded command 'uptime' from /Stats/uptime.js
Loaded command 'ping' from /Stats/ping.js
Loaded command 'settings' from /Misc/settings.js
Loaded command 'urban' from /Misc/urban.js
Loaded command 'time' from /Misc/time.js
Loaded command 'add-income-role' from /Administration/add-income-role.js
Loaded command 'reset-database' from /Administration/reset-database.js
Loaded command 'set-welcome-channel' from /Administration/set-welcome-channel.js
Loaded command 'add-shop-item' from /Administration/add-shop-item.js
Loaded command 'add-balance' from /Administration/add-balance.js
Loaded command 'remove-shop-item' from /Administration/remove-shop-item.js
Loaded command 'shop' from /Economy/shop.js
Loaded command 'balance' from /Economy/balance.js
Loaded command 'buy' from /Economy/buy.js
Loaded command 'view-inventory' from /Economy/inventory.js
Loaded command 'withdraw' from /Economy/withdraw.js
Loaded command 'deposit' from /Economy/deposit.js
Loaded command 'deploy-ticket' from /Ticket/deploy-ticket.js
Loaded event 'ready' from /ready.js
Database >> SQLite is connecting...
Database >> SQLite is ready! (Latency: 0.64 ms)
Loaded utility 'undefined' from /database.js
Logged in as Custom bot order - Arsh#8722.
somehow managed to get it working πŸ˜„ time to execute the command and see the bot die
NNKtv28
NNKtv28β€’9mo ago
called it xd
No description
d.js docs
d.js docsβ€’9mo ago
interface MessageCreateOptions The options for sending a class ButtonBuilder Represents a button builder.
NNKtv28
NNKtv28β€’9mo ago
const { SlashCommandBuilder } = require('discord.js');
const { EmbedBuilder, ButtonBuilder, ButtonStyle, MessageActionRow, ChannelType, MessageSelectMenu, MessageEmbed } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('deploy-ticket')
.setDescription('Deploy a button to open a ticket channel')
.addChannelOption(option => option
.setName('parent_category')
.setDescription('The parent category to create the ticket channel in')
.setRequired(false)
.addChannelTypes(ChannelType.GuildCategory)
),

async execute(interaction) {
// Create an embed to provide information about the ticket system
const embed = new EmbedBuilder()
.setAuthor({
name: "Ticket System",
})
.setTitle("Open a ticket")
.setDescription("Opening without a valid reason will be punished")
.setThumbnail("https://www.flaticon.com/free-icons/ticket\"")
.setColor("#00b0f4")
.setTimestamp();

//await interaction.editReply({ embeds: [embed] });

// Create a button that users can click to open a ticket
const ticketButton = new ButtonBuilder({
custom_id: 'open_ticket',
style: ButtonStyle.Primary,
label: 'Open Ticket',
});
// Send the embed with the select menu and button
await interaction.reply({ embeds: [embed], components: [ticketButton] });

},
};
const { SlashCommandBuilder } = require('discord.js');
const { EmbedBuilder, ButtonBuilder, ButtonStyle, MessageActionRow, ChannelType, MessageSelectMenu, MessageEmbed } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('deploy-ticket')
.setDescription('Deploy a button to open a ticket channel')
.addChannelOption(option => option
.setName('parent_category')
.setDescription('The parent category to create the ticket channel in')
.setRequired(false)
.addChannelTypes(ChannelType.GuildCategory)
),

async execute(interaction) {
// Create an embed to provide information about the ticket system
const embed = new EmbedBuilder()
.setAuthor({
name: "Ticket System",
})
.setTitle("Open a ticket")
.setDescription("Opening without a valid reason will be punished")
.setThumbnail("https://www.flaticon.com/free-icons/ticket\"")
.setColor("#00b0f4")
.setTimestamp();

//await interaction.editReply({ embeds: [embed] });

// Create a button that users can click to open a ticket
const ticketButton = new ButtonBuilder({
custom_id: 'open_ticket',
style: ButtonStyle.Primary,
label: 'Open Ticket',
});
// Send the embed with the select menu and button
await interaction.reply({ embeds: [embed], components: [ticketButton] });

},
};
i got this now and i get this now:
Error while executing "deploy-ticket" command: DiscordAPIError[50035]: Invalid Form Body
data.components[0][UNION_TYPE_CHOICES]: Value of field "type" must be one of (1,).
at handleErrors (D:\Discord bots\Custom bot order\node_modules\@discordjs\rest\dist\index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (D:\Discord bots\Custom bot order\node_modules\@discordjs\rest\dist\index.js:786:23)
at async _REST.request (D:\Discord bots\Custom bot order\node_modules\@discordjs\rest\dist\index.js:1218:22)
at async ChatInputCommandInteraction.reply (D:\Discord bots\Custom bot order\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:111:5)
at async Object.execute (D:\Discord bots\Custom bot order\commands\Ticket\deploy-ticket.js:36:5)
at async Object.execute (D:\Discord bots\Custom bot order\events\interactionCreate.js:24:7) {
requestBody: { files: [], json: { type: 4, data: [Object] } },
rawError: {
message: 'Invalid Form Body',
code: 50035,
errors: { data: [Object] }
},
code: 50035,
status: 400,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1156697885530931200/aW50ZXJhY3Rpb246MTE1NjY5Nzg4NTUzMDkzMTIwMDpONkE2R01kNURtak1Zd2ZCY3g0VXNpYnROTG1mTGRYM21IYW1NTkhheGFCU2xwQk9EVjluMDhEem9KVlY3cWtFd0FCZHF4ZEZYQVdiRE5tN25PTzFZOUVJWEZQSng1VjNjUWtFRWpmWFVuWEhOc1lkSjU0VXluVzd4ZjloZGlhVg/callback'
}
Error while executing "deploy-ticket" command: DiscordAPIError[50035]: Invalid Form Body
data.components[0][UNION_TYPE_CHOICES]: Value of field "type" must be one of (1,).
at handleErrors (D:\Discord bots\Custom bot order\node_modules\@discordjs\rest\dist\index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (D:\Discord bots\Custom bot order\node_modules\@discordjs\rest\dist\index.js:786:23)
at async _REST.request (D:\Discord bots\Custom bot order\node_modules\@discordjs\rest\dist\index.js:1218:22)
at async ChatInputCommandInteraction.reply (D:\Discord bots\Custom bot order\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:111:5)
at async Object.execute (D:\Discord bots\Custom bot order\commands\Ticket\deploy-ticket.js:36:5)
at async Object.execute (D:\Discord bots\Custom bot order\events\interactionCreate.js:24:7) {
requestBody: { files: [], json: { type: 4, data: [Object] } },
rawError: {
message: 'Invalid Form Body',
code: 50035,
errors: { data: [Object] }
},
code: 50035,
status: 400,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1156697885530931200/aW50ZXJhY3Rpb246MTE1NjY5Nzg4NTUzMDkzMTIwMDpONkE2R01kNURtak1Zd2ZCY3g0VXNpYnROTG1mTGRYM21IYW1NTkhheGFCU2xwQk9EVjluMDhEem9KVlY3cWtFd0FCZHF4ZEZYQVdiRE5tN25PTzFZOUVJWEZQSng1VjNjUWtFRWpmWFVuWEhOc1lkSjU0VXluVzd4ZjloZGlhVg/callback'
}
what do i do @wolvinny🌈
Unknown User
Unknown Userβ€’9mo ago
Message Not Public
Sign In & Join Server To View
NNKtv28
NNKtv28β€’9mo ago
ohh i need to import it from discord.js right?
Unknown User
Unknown Userβ€’9mo ago
Message Not Public
Sign In & Join Server To View
NNKtv28
NNKtv28β€’9mo ago
like this right?
No description
Unknown User
Unknown Userβ€’9mo ago
Message Not Public
Sign In & Join Server To View
NNKtv28
NNKtv28β€’9mo ago
yeah ik i usually do it but ijust forgot
NNKtv28
NNKtv28β€’9mo ago
YESSSS
No description
NNKtv28
NNKtv28β€’9mo ago
yall are the best now i need to make it so that when i press the button, it opens a channel under a certain channel category is there any way to specify that?
NNKtv28
NNKtv28β€’9mo ago
this is what i use to listen to when someone presses the button
No description
NNKtv28
NNKtv28β€’9mo ago
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
const TicketModel = require('../models/ticket');

client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});

client.on('interactionCreate', async (interaction) => {
if (!interaction.isButton()) return;

if (interaction.customId === 'open_ticket') {
try {
// Create a new ticket channel
const categoryID = '914137560554346849'; // Replace with the actual category ID
const channelName = `ticket-${interaction.user.username}`;
const ticketChannel = await interaction.guild.channels.create(channelName, {
type: 'GUILD_TEXT',
parent: categoryID,
});

// Set permissions for the user
await ticketChannel.permissionOverwrites.create(interaction.user.id, {
SEND_MESSAGES: true,
VIEW_CHANNEL: true,
MANAGE_MESSAGES: false,
});

// Respond to the interaction
await interaction.reply(`Your ticket channel ${ticketChannel} has been created.`);

// Save ticket information in your database (if applicable)
// Example: TicketModel.create({ userID: interaction.user.id, channelID: ticketChannel.id });
} catch (error) {
console.error('Error while handling ticket creation:', error);
interaction.reply('An error occurred while creating your ticket channel.');
}
}
});
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
const TicketModel = require('../models/ticket');

client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});

client.on('interactionCreate', async (interaction) => {
if (!interaction.isButton()) return;

if (interaction.customId === 'open_ticket') {
try {
// Create a new ticket channel
const categoryID = '914137560554346849'; // Replace with the actual category ID
const channelName = `ticket-${interaction.user.username}`;
const ticketChannel = await interaction.guild.channels.create(channelName, {
type: 'GUILD_TEXT',
parent: categoryID,
});

// Set permissions for the user
await ticketChannel.permissionOverwrites.create(interaction.user.id, {
SEND_MESSAGES: true,
VIEW_CHANNEL: true,
MANAGE_MESSAGES: false,
});

// Respond to the interaction
await interaction.reply(`Your ticket channel ${ticketChannel} has been created.`);

// Save ticket information in your database (if applicable)
// Example: TicketModel.create({ userID: interaction.user.id, channelID: ticketChannel.id });
} catch (error) {
console.error('Error while handling ticket creation:', error);
interaction.reply('An error occurred while creating your ticket channel.');
}
}
});
d.js docs
d.js docsβ€’9mo ago
method GuildChannelManager#create() Creates a new channel in the guild.
Unknown User
Unknown Userβ€’9mo ago
Message Not Public
Sign In & Join Server To View
treble/luna
treble/lunaβ€’9mo ago
thats also v13 so just dont ask chatgpt and follow the guide
NNKtv28
NNKtv28β€’9mo ago
hehe i will πŸ˜‰
Unknown User
Unknown Userβ€’9mo ago
Message Not Public
Sign In & Join Server To View
NNKtv28
NNKtv28β€’9mo ago
πŸ’€ thing is ive spend 3 days on this thing and i barely did any progress cause i try to watch tutorials and read docs but most times i dont understand anything at all so easyest option is chatgpt
treble/luna
treble/lunaβ€’9mo ago
chatgpt is what made you end up here so maybe consider following the guide and if you dont understand the guide i recommend learning the basics of js first
NNKtv28
NNKtv28β€’9mo ago
i do know the basics of js but todays not my most brightest day πŸ’€ i cant find the parent property, is it from discord.js V13?
d.js docs
d.js docsβ€’9mo ago
property TextChannel#parent The category parent of this channel
NNKtv28
NNKtv28β€’9mo ago
i guess its like this parent: TicketParentChannel,
treble/luna
treble/lunaβ€’9mo ago
yes
NNKtv28
NNKtv28β€’9mo ago
what happens if parent = Null? will the channel create somewhere random?
treble/luna
treble/lunaβ€’9mo ago
it will create a channel without a parent
NNKtv28
NNKtv28β€’9mo ago
oh alright thats fine
treble/luna
treble/lunaβ€’9mo ago
probablt at the top of the guild
NNKtv28
NNKtv28β€’9mo ago
const { Client, GatewayIntentBits, PermissionFlagsBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
const TicketModel = require('../models/ticket');

//const TicketID = TicketModel.TicketID;
const TicketParentChannel = TicketModel.TicketParentChannel;

client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});

client.on('interactionCreate', async (interaction) => {
if (!interaction.isButton()) return;

if (interaction.customId === 'open_ticket') {
try {
// Create a new ticket channel
guild.channels.create({
name: `Ticket - ${interaction.user.username}`,
type: ChannelType.GuildText,
parent: TicketParentChannel,
permissionOverwrites: [
{
id: message.author.id,
allow: [PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages],
},
],
})

// Respond to the interaction
await interaction.reply(`Your ticket channel ${ticketChannel} has been created.`);

// Save ticket information in your database (if applicable)
// Example: TicketModel.create({ userID: interaction.user.id, channelID: ticketChannel.id });
} catch (error) {
console.error('Error while handling ticket creation:', error);
interaction.reply('An error occurred while creating your ticket channel.');
}
}
});
const { Client, GatewayIntentBits, PermissionFlagsBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
const TicketModel = require('../models/ticket');

//const TicketID = TicketModel.TicketID;
const TicketParentChannel = TicketModel.TicketParentChannel;

client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});

client.on('interactionCreate', async (interaction) => {
if (!interaction.isButton()) return;

if (interaction.customId === 'open_ticket') {
try {
// Create a new ticket channel
guild.channels.create({
name: `Ticket - ${interaction.user.username}`,
type: ChannelType.GuildText,
parent: TicketParentChannel,
permissionOverwrites: [
{
id: message.author.id,
allow: [PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages],
},
],
})

// Respond to the interaction
await interaction.reply(`Your ticket channel ${ticketChannel} has been created.`);

// Save ticket information in your database (if applicable)
// Example: TicketModel.create({ userID: interaction.user.id, channelID: ticketChannel.id });
} catch (error) {
console.error('Error while handling ticket creation:', error);
interaction.reply('An error occurred while creating your ticket channel.');
}
}
});
did i link it right with the button? or do i need to specify the buttons script and then call the button custom_id?
treble/luna
treble/lunaβ€’9mo ago
have you tried your code
NNKtv28
NNKtv28β€’9mo ago
yeah, gives interaction error and no console feedback
treble/luna
treble/lunaβ€’9mo ago
does your event fire at all ah why do you construct a new client there? you have to construct 1 client and log in with that one
d.js docs
d.js docsβ€’9mo ago
guide Creating Your Bot: Event handling read moreguide Creating Your Bot: Command handling read more
treble/luna
treble/lunaβ€’9mo ago
use that to handle events and commands
NNKtv28
NNKtv28β€’9mo ago
No description
treble/luna
treble/lunaβ€’9mo ago
just you having those folders wont magically handle your commands / events
NNKtv28
NNKtv28β€’9mo ago
yeah ik i load the events in the index.js file and the commands too
treble/luna
treble/lunaβ€’9mo ago
then why did you construct a new client? you have the events right there already
NNKtv28
NNKtv28β€’9mo ago
u mean i need to do this
module.exports = {
name: Events.ticketEvent,
once: true,
execute(client) {

}
}
module.exports = {
name: Events.ticketEvent,
once: true,
execute(client) {

}
}
instead of client.on('interactionCreate', async (interaction) => { ?
Unknown User
Unknown Userβ€’9mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docsβ€’9mo ago
method BaseInteraction#isButton() Indicates whether this interaction is a ButtonInteraction.
NNKtv28
NNKtv28β€’9mo ago
const { Client, GatewayIntentBits, PermissionFlagsBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
const TicketModel = require('../models/ticket');

//const TicketID = TicketModel.TicketID;
const TicketParentChannel = TicketModel.TicketParentChannel;

module.exports = {
name: "ticketEvent",
once: true,

async execute(client) {
if (!interactionCreate.isButton()) return;

if (interactionCreate.customId === 'open_ticket') {
try {
// Create a new ticket channel
guild.channels.create({
name: `Ticket - ${interaction.user.username}`,
type: ChannelType.GuildText,
parent: TicketParentChannel,
permissionOverwrites: [
{
id: message.author.id,
allow: [PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages],
},
],
})

// Respond to the interaction
await interaction.reply(`Your ticket channel ${ticketChannel} has been created.`);

// Save ticket information in your database (if applicable)
// Example: TicketModel.create({ userID: interaction.user.id, channelID: ticketChannel.id });
} catch (error) {
console.error('Error while handling ticket creation:', error);
interaction.reply('An error occurred while creating your ticket channel.');
}
}
}
}
const { Client, GatewayIntentBits, PermissionFlagsBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
const TicketModel = require('../models/ticket');

//const TicketID = TicketModel.TicketID;
const TicketParentChannel = TicketModel.TicketParentChannel;

module.exports = {
name: "ticketEvent",
once: true,

async execute(client) {
if (!interactionCreate.isButton()) return;

if (interactionCreate.customId === 'open_ticket') {
try {
// Create a new ticket channel
guild.channels.create({
name: `Ticket - ${interaction.user.username}`,
type: ChannelType.GuildText,
parent: TicketParentChannel,
permissionOverwrites: [
{
id: message.author.id,
allow: [PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages],
},
],
})

// Respond to the interaction
await interaction.reply(`Your ticket channel ${ticketChannel} has been created.`);

// Save ticket information in your database (if applicable)
// Example: TicketModel.create({ userID: interaction.user.id, channelID: ticketChannel.id });
} catch (error) {
console.error('Error while handling ticket creation:', error);
interaction.reply('An error occurred while creating your ticket channel.');
}
}
}
}
Unknown User
Unknown Userβ€’9mo ago
Message Not Public
Sign In & Join Server To View
treble/luna
treble/lunaβ€’9mo ago
also again there is no ticketEvent
NNKtv28
NNKtv28β€’9mo ago
forgot the ""
treble/luna
treble/lunaβ€’9mo ago
and you never even defined that variable
NNKtv28
NNKtv28β€’9mo ago
wdym? where am i making a new client? nvm just saw it
Unknown User
Unknown Userβ€’9mo ago
Message Not Public
Sign In & Join Server To View
NNKtv28
NNKtv28β€’9mo ago
didnt even see that
Unknown User
Unknown Userβ€’9mo ago
Message Not Public
Sign In & Join Server To View
NNKtv28
NNKtv28β€’9mo ago
half of it ig, most is copy paste from the other events and everything they have similar πŸ’€
NNKtv28
NNKtv28β€’9mo ago
im reading the https://discordjs.guide/creating-your-bot/event-handling.html#individual-event-files and i see that they also added some stuff t o interactionCreate.js
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
treble/luna
treble/lunaβ€’9mo ago
yep
NNKtv28
NNKtv28β€’9mo ago
time to figure out what i need to add πŸ’€ should i move
if (interactionCreate.customId === 'open_ticket') {
try {
// Create a new ticket channel
guild.channels.create({
name: `Ticket - ${interaction.user.username}`,
type: ChannelType.GuildText,
parent: TicketParentChannel,
permissionOverwrites: [
{
id: message.author.id,
allow: [PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages],
},
],
})

// Respond to the interaction
await interaction.reply(`Your ticket channel ${ticketChannel} has been created.`);

// Save ticket information in your database (if applicable)
// Example: TicketModel.create({ userID: interaction.user.id, channelID: ticketChannel.id });
} catch (error) {
console.error('Error while handling ticket creation:', error);
interaction.reply('An error occurred while creating your ticket channel.');
}
}
if (interactionCreate.customId === 'open_ticket') {
try {
// Create a new ticket channel
guild.channels.create({
name: `Ticket - ${interaction.user.username}`,
type: ChannelType.GuildText,
parent: TicketParentChannel,
permissionOverwrites: [
{
id: message.author.id,
allow: [PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages],
},
],
})

// Respond to the interaction
await interaction.reply(`Your ticket channel ${ticketChannel} has been created.`);

// Save ticket information in your database (if applicable)
// Example: TicketModel.create({ userID: interaction.user.id, channelID: ticketChannel.id });
} catch (error) {
console.error('Error while handling ticket creation:', error);
interaction.reply('An error occurred while creating your ticket channel.');
}
}
to interactionCreate,js? or make it a function and call it from interactionCreate.js?
treble/luna
treble/lunaβ€’9mo ago
if you check your interaction types correclty you're better off making it a function and make a button handler
NNKtv28
NNKtv28β€’9mo ago
how does that work t he button handler? is it another .js file in events folder?
Unknown User
Unknown Userβ€’9mo ago
Message Not Public
Sign In & Join Server To View
NNKtv28
NNKtv28β€’9mo ago
so i made it a function
No description
NNKtv28
NNKtv28β€’9mo ago
ig now i need to pass it to interactionCreate and call it from there?
treble/luna
treble/lunaβ€’9mo ago
you did not define interactionCreate Nor do you properly export the function this is basic js at this point
NNKtv28
NNKtv28β€’9mo ago
im on 2 monsters and 5 hours of sleep πŸ™‚
Unknown User
Unknown Userβ€’9mo ago
Message Not Public
Sign In & Join Server To View
NNKtv28
NNKtv28β€’9mo ago
im studying web development so ik what no sleep is like πŸ™‚ is there any discord bot in v14 that i can just copy it from? cause im seing myself stuck with this for at least till next week πŸ’€
Unknown User
Unknown Userβ€’9mo ago
Message Not Public
Sign In & Join Server To View
NNKtv28
NNKtv28β€’9mo ago
T_T how is it that i can do it in python but not in JS πŸ’€ can i have multiple module.export per .js file or just 1?
treble/luna
treble/lunaβ€’9mo ago
just one but you can export multiple things not djs related however
NNKtv28
NNKtv28β€’9mo ago
oh alr
NNKtv28
NNKtv28β€’9mo ago
suggestions tempt me
No description
NNKtv28
NNKtv28β€’9mo ago
is this the right way? its in interactionCreate.js
No description
treble/luna
treble/lunaβ€’9mo ago
assuming you export those functions
NNKtv28
NNKtv28β€’9mo ago
also in the deploy-ticket command i dont see any option to specify a parent category even tho i defined it here:
module.exports = {
data: new SlashCommandBuilder()
.setName('deploy-ticket')
.setDescription('Deploy a button to open a ticket channel')
.addChannelOption(option => option
.setName('parent_category')
.setDescription('The parent category to create the ticket channel in')
.setRequired(false)
.addChannelTypes(ChannelType.GuildCategory)
),
module.exports = {
data: new SlashCommandBuilder()
.setName('deploy-ticket')
.setDescription('Deploy a button to open a ticket channel')
.addChannelOption(option => option
.setName('parent_category')
.setDescription('The parent category to create the ticket channel in')
.setRequired(false)
.addChannelTypes(ChannelType.GuildCategory)
),
No description
treble/luna
treble/lunaβ€’9mo ago
then you didn't redeploy
NNKtv28
NNKtv28β€’9mo ago
i needed to redeploy? i thought that was only to register the slash command, not to modify it indeed i needed to redeploy
treble/luna
treble/lunaβ€’9mo ago
well yeah editing your command wont magically edit it in discord
NNKtv28
NNKtv28β€’9mo ago
i thought it was enough with reloading the bot whats the difference between this
module.exports = {
name: "ticketEvent",

async execute(interaction)
{

}
}
module.exports = {
name: "ticketEvent",

async execute(interaction)
{

}
}
at the start of the module and module.exports = ticketEvent; at the end of the module?
treble/luna
treble/lunaβ€’9mo ago
what is ticketEvent defined as also this isnt djs related anymore So #useful-servers #other-js-ts #resources
NNKtv28
NNKtv28β€’9mo ago
async function ticketEvent(interaction) {
if (!interaction.isButton()) {
return;
}

const customId = interaction.customId;

if (customId === "ticket_create") {
await createTicket(interaction);
} else if (customId === "ticket_delete") {
await deleteTicket(interaction);
}
}
async function ticketEvent(interaction) {
if (!interaction.isButton()) {
return;
}

const customId = interaction.customId;

if (customId === "ticket_create") {
await createTicket(interaction);
} else if (customId === "ticket_delete") {
await deleteTicket(interaction);
}
}
async function createTicket(interaction) {
const guild = interaction.guild;
const user = interaction.user;

// Create a new ticket channel
guild.channels.create({
name: `Ticket - ${user.username}`,
type: ChannelType.GuildText,
parent: TicketParentChannel,
permissionOverwrites: [
{
id: user.id,
allow: [PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages],
},
],
})
// Respond to the interaction
await interaction.reply(`Your ticket channel has been created.`);
}

async function deleteTicket(interaction) {
const channel = interaction.channel;

// Delete the ticket channel
channel.delete();

// Respond to the interaction
await interaction.reply(`Your ticket channel has been deleted.`);
}
async function createTicket(interaction) {
const guild = interaction.guild;
const user = interaction.user;

// Create a new ticket channel
guild.channels.create({
name: `Ticket - ${user.username}`,
type: ChannelType.GuildText,
parent: TicketParentChannel,
permissionOverwrites: [
{
id: user.id,
allow: [PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages],
},
],
})
// Respond to the interaction
await interaction.reply(`Your ticket channel has been created.`);
}

async function deleteTicket(interaction) {
const channel = interaction.channel;

// Delete the ticket channel
channel.delete();

// Respond to the interaction
await interaction.reply(`Your ticket channel has been deleted.`);
}
treble/luna
treble/lunaβ€’9mo ago
and?
NNKtv28
NNKtv28β€’9mo ago
idk what im even doing at this point im just trying stuff i see tbh
treble/luna
treble/lunaβ€’9mo ago
you shouldn't do that You should have a strong js knowledge before beginning djs as per #rules 3
NNKtv28
NNKtv28β€’9mo ago
i never tryed doing such a hard bot, mostly i did was the typicall mod bot, but never got this far into it im about to toss the entire ticket idea πŸ’€
NNKtv28
NNKtv28β€’9mo ago
this is what i want to archive
No description
NNKtv28
NNKtv28β€’9mo ago
i did some progress πŸ˜„
No description
NNKtv28
NNKtv28β€’9mo ago
im not completely useless
NNKtv28
NNKtv28β€’9mo ago
i got it πŸ’€
No description
NNKtv28
NNKtv28β€’9mo ago
what u gona say now huh
ShompiFlen
ShompiFlenβ€’9mo ago
stop, people are here to help you, if you were told your js knowledge was lacking its because it was, and it makes it super difficult for us to try and help you, too. Its nice that you are making progress.
NNKtv28
NNKtv28β€’9mo ago
I was just kidding mate πŸ’€ Ik and i always apreciate everyone who helps me I ended up bringing the interactions to the index.js file
NNKtv28
NNKtv28β€’9mo ago
so the ticket gets created and crashes the bot when i try to ping staff
No description
No description
NNKtv28
NNKtv28β€’9mo ago
// Ping staff
client.on(Events.InteractionCreate, async interaction => {
if(interaction.isButton() && interaction.customId == "pingStaff" ) {
const StaffID = "1106128477528264774";

const roleMention = StaffID.map(id => `<@&${id}>`).join(" ");
const messageContent = `${roleMention}`;

const embed = new EmbedBuilder()
.setTitle("Staff Pinged")
.setDescription(`The staff have been pinged, please wait 2-4 hours max`)
.setColor('Blue')
.setTimestamp()
.setFooter({ text: "Staff pinged At"})

await interaction.channel.send({
content: messageContent,
embeds: [embed]
})
await interaction.reply({
content: "You have succesfully pinged staff",
ephemeral: true
})
}
});
// Ping staff
client.on(Events.InteractionCreate, async interaction => {
if(interaction.isButton() && interaction.customId == "pingStaff" ) {
const StaffID = "1106128477528264774";

const roleMention = StaffID.map(id => `<@&${id}>`).join(" ");
const messageContent = `${roleMention}`;

const embed = new EmbedBuilder()
.setTitle("Staff Pinged")
.setDescription(`The staff have been pinged, please wait 2-4 hours max`)
.setColor('Blue')
.setTimestamp()
.setFooter({ text: "Staff pinged At"})

await interaction.channel.send({
content: messageContent,
embeds: [embed]
})
await interaction.reply({
content: "You have succesfully pinged staff",
ephemeral: true
})
}
});
and i get this error:
node:events:495
throw er; // Unhandled 'error' event
^

TypeError: StaffID.map is not a function
at Client.<anonymous> (E:\Discord bots\Custom bot order\index.js:182:33)
at Client.emit (node:events:529:35)
at module.exports [as INTERACTION_CREATE] (E:\Discord bots\Custom bot order\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (E:\Discord bots\Custom bot order\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (E:\Discord bots\Custom bot order\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (E:\Discord bots\Custom bot order\node_modules\@vladfrangu\async_event_emitter\dist\index.js:282:31)
at WebSocketShard.<anonymous> (E:\Discord bots\Custom bot order\node_modules\@discordjs\ws\dist\index.js:1173:51)
at WebSocketShard.emit (E:\Discord bots\Custom bot order\node_modules\@vladfrangu\async_event_emitter\dist\index.js:282:31)
at WebSocketShard.onMessage (E:\Discord bots\Custom bot order\node_modules\@discordjs\ws\dist\index.js:988:14)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:398:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)

Node.js v18.18.0
node:events:495
throw er; // Unhandled 'error' event
^

TypeError: StaffID.map is not a function
at Client.<anonymous> (E:\Discord bots\Custom bot order\index.js:182:33)
at Client.emit (node:events:529:35)
at module.exports [as INTERACTION_CREATE] (E:\Discord bots\Custom bot order\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (E:\Discord bots\Custom bot order\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (E:\Discord bots\Custom bot order\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (E:\Discord bots\Custom bot order\node_modules\@vladfrangu\async_event_emitter\dist\index.js:282:31)
at WebSocketShard.<anonymous> (E:\Discord bots\Custom bot order\node_modules\@discordjs\ws\dist\index.js:1173:51)
at WebSocketShard.emit (E:\Discord bots\Custom bot order\node_modules\@vladfrangu\async_event_emitter\dist\index.js:282:31)
at WebSocketShard.onMessage (E:\Discord bots\Custom bot order\node_modules\@discordjs\ws\dist\index.js:988:14)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:398:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)

Node.js v18.18.0
ShompiFlen
ShompiFlenβ€’9mo ago
you are trying to call map on a string const StaffID = "1106128477528264774";
NNKtv28
NNKtv28β€’9mo ago
so i just remove the .map? Nope dont work how should it be?
ShompiFlen
ShompiFlenβ€’9mo ago
you have one id which is a string and it seems like you want to format it as a mention, do that its a string, you can preformat it no need to go through a function
NNKtv28
NNKtv28β€’9mo ago
oh alr thxx
NNKtv28
NNKtv28β€’9mo ago
yess it worked
No description
NNKtv28
NNKtv28β€’9mo ago
great now the delete button ticket broke and idk why:
// Delete ticket
client.on(Events.InteractionCreate, async interaction => {

if(interaction.isButton() && interaction.customId == "ticket_delete"){
delete tickets[interaction.user.id];
interaction.channel.delete();
const dmEmbed = new EmbedBuilder()
.setTitle("Ticket Closed")
.setDescription(`Your ticket has been closed.`)
.setColor(0x00FFFF)
.setTimestamp()
.setFooter({ text: "Ticket closed by " + interaction.user.username, iconURL: interaction.user.displayAvatarURL() })

const dmBtn = new ButtonBuilder()
.setLabel('Return')
.setStyle(ButtonStyle.Link)
.setURL('https://discord.com/channels/1028911977055137893/1155817477922623520')

const dmRow = new ActionRowBuilder()
.addComponents(dmBtn)


interaction.user.send({ embeds: [dmEmbed], components: [dmRow] });
return;
}
})
}
})
// Delete ticket
client.on(Events.InteractionCreate, async interaction => {

if(interaction.isButton() && interaction.customId == "ticket_delete"){
delete tickets[interaction.user.id];
interaction.channel.delete();
const dmEmbed = new EmbedBuilder()
.setTitle("Ticket Closed")
.setDescription(`Your ticket has been closed.`)
.setColor(0x00FFFF)
.setTimestamp()
.setFooter({ text: "Ticket closed by " + interaction.user.username, iconURL: interaction.user.displayAvatarURL() })

const dmBtn = new ButtonBuilder()
.setLabel('Return')
.setStyle(ButtonStyle.Link)
.setURL('https://discord.com/channels/1028911977055137893/1155817477922623520')

const dmRow = new ActionRowBuilder()
.addComponents(dmBtn)


interaction.user.send({ embeds: [dmEmbed], components: [dmRow] });
return;
}
})
}
})
treble/luna
treble/lunaβ€’9mo ago
And which code runs Since you have 2x code that handles the same button
NNKtv28
NNKtv28β€’9mo ago
wait leme see cuz i actually dont know if its the on in interactionCreate is the old one indeed it was the old one so yea this is the one that runs it
treble/luna
treble/lunaβ€’9mo ago
There is no code to actually delete the channel Nor do you reply to the interaction
NNKtv28
NNKtv28β€’9mo ago
so this does nothing? interaction.channel.delete(); or should i specify the channel inside () like ('${channel}')
treble/luna
treble/lunaβ€’9mo ago
It deletes the channel the interaction happened in
NNKtv28
NNKtv28β€’9mo ago
yeah that the objective delete the channel where the delete button was pressed
treble/luna
treble/lunaβ€’9mo ago
but since nothing happens at all i doubt that code is even being reached
NNKtv28
NNKtv28β€’9mo ago
yep its not reaching πŸ’€
treble/luna
treble/lunaβ€’9mo ago
i'm pretty sure you just created a new client again Because your other buttons work So i dont see why you create a new event
NNKtv28
NNKtv28β€’9mo ago
dont think so, since im in the index.js i use Client.on so i dont need to make a new client
treble/luna
treble/lunaβ€’9mo ago
You already have an interactionCreate event where you handle the other buttons You need 1, not multiple listeners
NNKtv28
NNKtv28β€’9mo ago
so i can move the code in side this client.On
// Delete ticket
client.on(Events.InteractionCreate, async interaction => {


if(interaction.isButton() && interaction.customId == "ticket_delete"){
console.log("Delete button was pressed");
delete tickets[interaction.user.id];
interaction.channel.delete();
const dmEmbed = new EmbedBuilder()
.setTitle("Ticket Closed")
.setDescription(`Your ticket has been closed.`)
.setColor(0x00FFFF)
.setTimestamp()
.setFooter({ text: "Ticket closed by " + interaction.user.username, iconURL: interaction.user.displayAvatarURL() })

const dmBtn = new ButtonBuilder()
.setLabel('Return')
.setStyle(ButtonStyle.Link)
.setURL('https://discord.com/channels/1028911977055137893/1155817477922623520')

const dmRow = new ActionRowBuilder()
.addComponents(dmBtn)

interaction.user.reply({ embeds: [dmEmbed], components: [dmRow] });
return;
}
})
// Delete ticket
client.on(Events.InteractionCreate, async interaction => {


if(interaction.isButton() && interaction.customId == "ticket_delete"){
console.log("Delete button was pressed");
delete tickets[interaction.user.id];
interaction.channel.delete();
const dmEmbed = new EmbedBuilder()
.setTitle("Ticket Closed")
.setDescription(`Your ticket has been closed.`)
.setColor(0x00FFFF)
.setTimestamp()
.setFooter({ text: "Ticket closed by " + interaction.user.username, iconURL: interaction.user.displayAvatarURL() })

const dmBtn = new ButtonBuilder()
.setLabel('Return')
.setStyle(ButtonStyle.Link)
.setURL('https://discord.com/channels/1028911977055137893/1155817477922623520')

const dmRow = new ActionRowBuilder()
.addComponents(dmBtn)

interaction.user.reply({ embeds: [dmEmbed], components: [dmRow] });
return;
}
})
inside here?
// Ping staff
client.on(Events.InteractionCreate, async interaction => {
if(interaction.isButton() && interaction.customId == "pingStaff" ) {
//const StaffID = "1106128477528264774";
const StaffID = AdminRoles.role_id;

if(!StaffID){
interaction.reply("No admin roles have been established");
}else{
const roleMention = `<@&${StaffID}>`;
const messageContent = `${roleMention}`;
const embed = new EmbedBuilder()
.setTitle("Staff Pinged")
.setDescription(`The staff have been pinged, please wait 2-4 hours max`)
.setColor('Blue')
.setTimestamp()
.setFooter({ text: "Staff pinged At"})

await interaction.channel.send({
content: messageContent,
embeds: [embed]
})
await interaction.reply({
content: "You have succesfully pinged staff",
ephemeral: true
})
}
}
});
// Ping staff
client.on(Events.InteractionCreate, async interaction => {
if(interaction.isButton() && interaction.customId == "pingStaff" ) {
//const StaffID = "1106128477528264774";
const StaffID = AdminRoles.role_id;

if(!StaffID){
interaction.reply("No admin roles have been established");
}else{
const roleMention = `<@&${StaffID}>`;
const messageContent = `${roleMention}`;
const embed = new EmbedBuilder()
.setTitle("Staff Pinged")
.setDescription(`The staff have been pinged, please wait 2-4 hours max`)
.setColor('Blue')
.setTimestamp()
.setFooter({ text: "Staff pinged At"})

await interaction.channel.send({
content: messageContent,
embeds: [embed]
})
await interaction.reply({
content: "You have succesfully pinged staff",
ephemeral: true
})
}
}
});
treble/luna
treble/lunaβ€’9mo ago
yep there
NNKtv28
NNKtv28β€’9mo ago
and have only one client.on(Events.InteractionCreate, async interaction => { oh alr thx yeah makes sense now that i think about it now not even staff ping button works 🀣
client.on(Events.InteractionCreate, async interaction => {
// Delete ticket
if(interaction.isButton() && interaction.customId == "ticket_delete"){
console.log("Delete button was pressed");
delete tickets[interaction.user.id];
interaction.channel.delete();
const dmEmbed = new EmbedBuilder()
.setTitle("Ticket Closed")
.setDescription(`Your ticket has been closed.`)
.setColor(0x00FFFF)
.setTimestamp()
.setFooter({ text: "Ticket closed by " + interaction.user.username, iconURL: interaction.user.displayAvatarURL() })

const dmBtn = new ButtonBuilder()
.setLabel('Return')
.setStyle(ButtonStyle.Link)
.setURL('https://discord.com/channels/1028911977055137893/1155817477922623520')

const dmRow = new ActionRowBuilder()
.addComponents(dmBtn)

interaction.user.reply({ embeds: [dmEmbed], components: [dmRow] });
return;
}

// Ping staff
if(interaction.isButton() && interaction.customId == "pingStaff" ) {
//const StaffID = "1106128477528264774";
const StaffID = AdminRoles.role_id;

if(!StaffID){
interaction.reply("No admin roles have been established");
}else{
const roleMention = `<@&${StaffID}>`;
const messageContent = `${roleMention}`;
const embed = new EmbedBuilder()
.setTitle("Staff Pinged")
.setDescription(`The staff have been pinged, please wait 2-4 hours max`)
.setColor('Blue')
.setTimestamp()
.setFooter({ text: "Staff pinged At"})

await interaction.channel.send({
content: messageContent,
embeds: [embed]
})
await interaction.reply({
content: "You have succesfully pinged staff",
ephemeral: true
})
}
}
})
}
})
client.on(Events.InteractionCreate, async interaction => {
// Delete ticket
if(interaction.isButton() && interaction.customId == "ticket_delete"){
console.log("Delete button was pressed");
delete tickets[interaction.user.id];
interaction.channel.delete();
const dmEmbed = new EmbedBuilder()
.setTitle("Ticket Closed")
.setDescription(`Your ticket has been closed.`)
.setColor(0x00FFFF)
.setTimestamp()
.setFooter({ text: "Ticket closed by " + interaction.user.username, iconURL: interaction.user.displayAvatarURL() })

const dmBtn = new ButtonBuilder()
.setLabel('Return')
.setStyle(ButtonStyle.Link)
.setURL('https://discord.com/channels/1028911977055137893/1155817477922623520')

const dmRow = new ActionRowBuilder()
.addComponents(dmBtn)

interaction.user.reply({ embeds: [dmEmbed], components: [dmRow] });
return;
}

// Ping staff
if(interaction.isButton() && interaction.customId == "pingStaff" ) {
//const StaffID = "1106128477528264774";
const StaffID = AdminRoles.role_id;

if(!StaffID){
interaction.reply("No admin roles have been established");
}else{
const roleMention = `<@&${StaffID}>`;
const messageContent = `${roleMention}`;
const embed = new EmbedBuilder()
.setTitle("Staff Pinged")
.setDescription(`The staff have been pinged, please wait 2-4 hours max`)
.setColor('Blue')
.setTimestamp()
.setFooter({ text: "Staff pinged At"})

await interaction.channel.send({
content: messageContent,
embeds: [embed]
})
await interaction.reply({
content: "You have succesfully pinged staff",
ephemeral: true
})
}
}
})
}
})
treble/luna
treble/lunaβ€’9mo ago
first of all, <User>.reply doesnt exist
d.js docs
d.js docsβ€’9mo ago
If you aren't getting any errors, try to place console.log checkpoints throughout your code to find out where execution stops. - Once you do, log relevant values and if-conditions - More sophisticated debugging methods are breakpoints and runtime inspections: learn more
NNKtv28
NNKtv28β€’9mo ago
im an idiot the issue was that i needed to define (${'channel}') interaction.channel.delete(${channel}); like that now it deletes the channel πŸ’€ although it does not like my ping button:
E:\Discord bots\Custom bot order\node_modules\@discordjs\rest\dist\index.js:687
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^

DiscordAPIError[10062]: Unknown interaction
at handleErrors (E:\Discord bots\Custom bot order\node_modules\@discordjs\rest\dist\index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (E:\Discord bots\Custom bot order\node_modules\@discordjs\rest\dist\index.js:786:23)
at async _REST.request (E:\Discord bots\Custom bot order\node_modules\@discordjs\rest\dist\index.js:1218:22)
at async ButtonInteraction.reply (E:\Discord bots\Custom bot order\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:111:5) {
requestBody: {
files: [],
json: {
type: 4,
data: {
content: 'No admin roles have been established',
tts: false,
nonce: undefined,
embeds: undefined,
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined
}
}
},
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1156888108877479938/aW50ZXJhY3Rpb246MTE1Njg4ODEwODg3NzQ3OTkzODo2U1VRempWS1NSamVBZUxhRHE4Tm44eTIyY3hpTUx6anJGVVg1TkY1SnB1Nm94THhJWEpSbTh3YmlyVmhXQTZzaFhwQUtwaXY0Y3VkYnl6dUx4SUlWWDNqZHNZQ2lmVEZvYnBCNTJaaWxLSjVoYnY4R0hoNHNJQnlZcmpuUXdXWA/callback'
}

Node.js v18.18.0
E:\Discord bots\Custom bot order\node_modules\@discordjs\rest\dist\index.js:687
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^

DiscordAPIError[10062]: Unknown interaction
at handleErrors (E:\Discord bots\Custom bot order\node_modules\@discordjs\rest\dist\index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (E:\Discord bots\Custom bot order\node_modules\@discordjs\rest\dist\index.js:786:23)
at async _REST.request (E:\Discord bots\Custom bot order\node_modules\@discordjs\rest\dist\index.js:1218:22)
at async ButtonInteraction.reply (E:\Discord bots\Custom bot order\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:111:5) {
requestBody: {
files: [],
json: {
type: 4,
data: {
content: 'No admin roles have been established',
tts: false,
nonce: undefined,
embeds: undefined,
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined
}
}
},
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1156888108877479938/aW50ZXJhY3Rpb246MTE1Njg4ODEwODg3NzQ3OTkzODo2U1VRempWS1NSamVBZUxhRHE4Tm44eTIyY3hpTUx6anJGVVg1TkY1SnB1Nm94THhJWEpSbTh3YmlyVmhXQTZzaFhwQUtwaXY0Y3VkYnl6dUx4SUlWWDNqZHNZQ2lmVEZvYnBCNTJaaWxLSjVoYnY4R0hoNHNJQnlZcmpuUXdXWA/callback'
}

Node.js v18.18.0
im not even gona ask about that cause il get 20 people shouting at me that its not discord.js related πŸ’€
d.js docs
d.js docsβ€’9mo ago
Common causes of DiscordAPIError[10062]: Unknown interaction: - Initial response took more than 3 seconds ➞ defer the response *. - Wrong interaction object inside a collector. - Two processes handling the same command (the first consumes the interaction, so it won't be valid for the other instance) * Note: you cannot defer modal or autocomplete value responses
NNKtv28
NNKtv28β€’9mo ago
im pretty sure its because of my sqlite database that im probably calling the AdminRole variable wrong
NNKtv28
NNKtv28β€’9mo ago
even though i do get the bots response cause theres not any role stored yet
No description
treble/luna
treble/lunaβ€’9mo ago
You shouldn't have to pass in the channel to delete
NNKtv28
NNKtv28β€’9mo ago
// Delete ticket
if(interaction.isButton() && interaction.customId == "ticket_delete"){
console.log("Delete button was pressed");
delete tickets[interaction.user.id];
interaction.channel.delete(`${channel}`);
const dmEmbed = new EmbedBuilder()
.setTitle("Ticket Closed")
.setDescription(`Your ticket has been closed.`)
.setColor(0x00FFFF)
.setTimestamp()
.setFooter({ text: "Ticket closed by " + interaction.user.username, iconURL: interaction.user.displayAvatarURL() })

const dmBtn = new ButtonBuilder()
.setLabel('Return')
.setStyle(ButtonStyle.Link)
.setURL('https://discord.com/channels/1028911977055137893/1155817477922623520')

const dmRow = new ActionRowBuilder()
.addComponents(dmBtn)

interaction.reply({ embeds: [dmEmbed], components: [dmRow] });
return;
}
// Delete ticket
if(interaction.isButton() && interaction.customId == "ticket_delete"){
console.log("Delete button was pressed");
delete tickets[interaction.user.id];
interaction.channel.delete(`${channel}`);
const dmEmbed = new EmbedBuilder()
.setTitle("Ticket Closed")
.setDescription(`Your ticket has been closed.`)
.setColor(0x00FFFF)
.setTimestamp()
.setFooter({ text: "Ticket closed by " + interaction.user.username, iconURL: interaction.user.displayAvatarURL() })

const dmBtn = new ButtonBuilder()
.setLabel('Return')
.setStyle(ButtonStyle.Link)
.setURL('https://discord.com/channels/1028911977055137893/1155817477922623520')

const dmRow = new ActionRowBuilder()
.addComponents(dmBtn)

interaction.reply({ embeds: [dmEmbed], components: [dmRow] });
return;
}
for some reason i did seems like the delete button works after i open the ticket and the bot doesnt crash, once either i restart it or it crashes it doesnt work anymore
duck
duckβ€’9mo ago
this describes the behavior one might expect when using either a collector or otherwise a nested interactionCreate listener given that you're not using a collector, I'm assuming the latter, which means that the change you made to consolidate into 1 listener was completely reverted wolvinny is also correct, you don't need to pass a param for <GuildChannel>.delete() it accepts a string for the reason for deletion, but it's not required or being used to determine what channel to delete likely something else changed alongside your addition of this param so that it was simply perceived as this being the fix it's hard to say exactly what given that you've thus far made several seemingly random changes without understanding them
NNKtv28
NNKtv28β€’9mo ago
now THATS what i call a great explanation, and a good deduction wich is half right cuz the specification of the channel was actually a desperate try
client.on(Events.InteractionCreate, async interaction => {

// Ping staff
if(interaction.isButton() && interaction.customId == "pingStaff" ) {
//const StaffID = "1106128477528264774";
const StaffID = AdminRoles.role_id;

if(!StaffID){
interaction.reply("No admin roles have been established");
}else{
const roleMention = `<@&${StaffID}>`;
const messageContent = `${roleMention}`;
const embed = new EmbedBuilder()
.setTitle("Staff Pinged")
.setDescription(`The staff have been pinged, please wait 2-4 hours max`)
.setColor('Blue')
.setTimestamp()
.setFooter({ text: "Staff pinged At"})

await interaction.channel.send({
content: messageContent,
embeds: [embed]
})
await interaction.reply({
content: "You have succesfully pinged staff",
ephemeral: true
})
}
}

// Delete ticket
if(interaction.isButton() && interaction.customId == "ticket_delete"){
console.log("Delete button was pressed");
delete tickets[interaction.user.id];
interaction.channel.delete(`${channel}`);
const dmEmbed = new EmbedBuilder()
.setTitle("Ticket Closed")
.setDescription(`Your ticket has been closed.`)
.setColor(0x00FFFF)
.setTimestamp()
.setFooter({ text: "Ticket closed by " + interaction.user.username, iconURL: interaction.user.displayAvatarURL() })

const dmBtn = new ButtonBuilder()
.setLabel('Return')
.setStyle(ButtonStyle.Link)
.setURL('https://discord.com/channels/1028911977055137893/1155817477922623520')

const dmRow = new ActionRowBuilder()
.addComponents(dmBtn)

interaction.reply({ embeds: [dmEmbed], components: [dmRow] });
return;
}
})
client.on(Events.InteractionCreate, async interaction => {

// Ping staff
if(interaction.isButton() && interaction.customId == "pingStaff" ) {
//const StaffID = "1106128477528264774";
const StaffID = AdminRoles.role_id;

if(!StaffID){
interaction.reply("No admin roles have been established");
}else{
const roleMention = `<@&${StaffID}>`;
const messageContent = `${roleMention}`;
const embed = new EmbedBuilder()
.setTitle("Staff Pinged")
.setDescription(`The staff have been pinged, please wait 2-4 hours max`)
.setColor('Blue')
.setTimestamp()
.setFooter({ text: "Staff pinged At"})

await interaction.channel.send({
content: messageContent,
embeds: [embed]
})
await interaction.reply({
content: "You have succesfully pinged staff",
ephemeral: true
})
}
}

// Delete ticket
if(interaction.isButton() && interaction.customId == "ticket_delete"){
console.log("Delete button was pressed");
delete tickets[interaction.user.id];
interaction.channel.delete(`${channel}`);
const dmEmbed = new EmbedBuilder()
.setTitle("Ticket Closed")
.setDescription(`Your ticket has been closed.`)
.setColor(0x00FFFF)
.setTimestamp()
.setFooter({ text: "Ticket closed by " + interaction.user.username, iconURL: interaction.user.displayAvatarURL() })

const dmBtn = new ButtonBuilder()
.setLabel('Return')
.setStyle(ButtonStyle.Link)
.setURL('https://discord.com/channels/1028911977055137893/1155817477922623520')

const dmRow = new ActionRowBuilder()
.addComponents(dmBtn)

interaction.reply({ embeds: [dmEmbed], components: [dmRow] });
return;
}
})
thats the code i did change its how it is right now also i did not revert rule 1 of coding, something works then dont touch it, ima apply that rule to this
interaction.channel.delete(`${channel}`);
interaction.channel.delete(`${channel}`);
duck
duckβ€’9mo ago
nobody said that you have to remove it just that you shouldn't consider that to be what fixed the issue that being said, are you not still using slash commands? at the beginning of the thread you were, but if this is the one and only interactionCreate listener you have, where are you handling command interactions?
NNKtv28
NNKtv28β€’9mo ago
i use slash commands since the start and deploy them usign node deploy-commands.js yeah all the commands what they need is to just access a sqlite database and thats all for example this deposit.js:
const { SlashCommandBuilder } = require("discord.js");
const BalanceModel = require("../../models/balance"); // Import your Balance model

module.exports = {
data: new SlashCommandBuilder()
.setName('deposit')
.setDescription("Deposit money from your cash balance into the bank.")
.addIntegerOption((option) =>
option.setName("amount").setDescription("The amount to deposit into the bank.").setRequired(true)
)
.setDMPermission(false),

async execute(interaction) {
await interaction.deferReply({ ephemeral: true });

const user = interaction.user;
const amount = interaction.options.getInteger("amount");

try {
// Check if the user's balance exists in the database
let userBalance = await BalanceModel.findOne({
where: { user_id: user.id },
});

if (!userBalance) {
userBalance = await BalanceModel.create({
user_id: user.id,
user_balance_cash: 0,
user_balance_bank: 0,
});
}

// Check if the user has enough cash to deposit
if (userBalance.user_balance_cash < amount) {
return interaction.editReply("You don't have enough cash to deposit that amount.");
}

// Deposit the money into the bank and deduct it from cash balance
userBalance.user_balance_cash -= amount;
userBalance.user_balance_bank += amount;

// Save the updated balance
await userBalance.save();

interaction.editReply(`You successfully deposited ${amount}$ into the bank.`);
} catch (error) {
console.error(error);
interaction.editReply("An error occurred while processing your deposit.");
}
},
};
const { SlashCommandBuilder } = require("discord.js");
const BalanceModel = require("../../models/balance"); // Import your Balance model

module.exports = {
data: new SlashCommandBuilder()
.setName('deposit')
.setDescription("Deposit money from your cash balance into the bank.")
.addIntegerOption((option) =>
option.setName("amount").setDescription("The amount to deposit into the bank.").setRequired(true)
)
.setDMPermission(false),

async execute(interaction) {
await interaction.deferReply({ ephemeral: true });

const user = interaction.user;
const amount = interaction.options.getInteger("amount");

try {
// Check if the user's balance exists in the database
let userBalance = await BalanceModel.findOne({
where: { user_id: user.id },
});

if (!userBalance) {
userBalance = await BalanceModel.create({
user_id: user.id,
user_balance_cash: 0,
user_balance_bank: 0,
});
}

// Check if the user has enough cash to deposit
if (userBalance.user_balance_cash < amount) {
return interaction.editReply("You don't have enough cash to deposit that amount.");
}

// Deposit the money into the bank and deduct it from cash balance
userBalance.user_balance_cash -= amount;
userBalance.user_balance_bank += amount;

// Save the updated balance
await userBalance.save();

interaction.editReply(`You successfully deposited ${amount}$ into the bank.`);
} catch (error) {
console.error(error);
interaction.editReply("An error occurred while processing your deposit.");
}
},
};
this is what the rest of commands looks like
duck
duckβ€’9mo ago
yes, and therefore somewhere you are receiving command interactions I don't see any code for it here https://discord.com/channels/222078108977594368/1156684794059567275/1157034503181709402 therefore you have not consolidated all interactionCreate listeners into 1 as wolvinny recommended
NNKtv28
NNKtv28β€’9mo ago
this is the interactionCreate.js code:
const { Events, WebhookClient } = require("discord.js");
const { errorWebhookURL } = require('../config.json');
const webhook = new WebhookClient({ url: errorWebhookURL });

module.exports = {
name: Events.InteractionCreate,
once: false,
async execute(interaction) {
if (!interaction.isCommand()) return;

const command = interaction.client.commands.get(interaction.commandName);

// If the command doesn't exist, log it and return.
if (!command) {
console.error(`No command matching "${interaction.commandName}" was found. Make sure the file exists.`);
await webhook.send(`No command matching "${interaction.commandName}" was found. Make sure the file exists.`);
return;
}

try {
await command.execute(interaction);
} catch (error) {
console.error(`Error while executing "${interaction.commandName}" command:`, error);

await interaction.reply({
content: "There was an error while executing this command. Our team has been notified.",
ephemeral: true,
});

// You can also log the error to a dedicated error channel or service for further debugging.
// Example: bot.channels.cache.get('error-channel-id').send(`Error while executing "${interaction.commandName}" command: ${error}`);
}

// ticket creation interaction
if (interaction.customId === "ticket_create") {
try {
await ticketEvent.execute(interaction);
} catch (error) {
console.error(`Error while handling ticket creation:`, error);
await interaction.reply({
content: "There was an error while handling your ticket creation. Our team has been notified.",
ephemeral: true,
});
}
}
},
};
const { Events, WebhookClient } = require("discord.js");
const { errorWebhookURL } = require('../config.json');
const webhook = new WebhookClient({ url: errorWebhookURL });

module.exports = {
name: Events.InteractionCreate,
once: false,
async execute(interaction) {
if (!interaction.isCommand()) return;

const command = interaction.client.commands.get(interaction.commandName);

// If the command doesn't exist, log it and return.
if (!command) {
console.error(`No command matching "${interaction.commandName}" was found. Make sure the file exists.`);
await webhook.send(`No command matching "${interaction.commandName}" was found. Make sure the file exists.`);
return;
}

try {
await command.execute(interaction);
} catch (error) {
console.error(`Error while executing "${interaction.commandName}" command:`, error);

await interaction.reply({
content: "There was an error while executing this command. Our team has been notified.",
ephemeral: true,
});

// You can also log the error to a dedicated error channel or service for further debugging.
// Example: bot.channels.cache.get('error-channel-id').send(`Error while executing "${interaction.commandName}" command: ${error}`);
}

// ticket creation interaction
if (interaction.customId === "ticket_create") {
try {
await ticketEvent.execute(interaction);
} catch (error) {
console.error(`Error while handling ticket creation:`, error);
await interaction.reply({
content: "There was an error while handling your ticket creation. Our team has been notified.",
ephemeral: true,
});
}
}
},
};
duck
duckβ€’9mo ago
on the first line of this execute function you return if the interaction is not a command interaction then later after handling commands, you attempt to handle what I assume is a button interaction an interaction will never be both a command interaction and a button interaction you'd want to rework the logic of this function so that it can accommodate both command and component interactions, then work from there that way the components being handled in this separate listener here https://discord.com/channels/222078108977594368/1156684794059567275/1157034503181709402 can be consolidated into one interactionCreate listener
NNKtv28
NNKtv28β€’9mo ago
ohhh alright so interactionCreate can only handle 1 interaction type?
duck
duckβ€’9mo ago
no, interactionCreate handles all interactions by returning on the first line if it's not a command interaction, you are only handling 1 type
NNKtv28
NNKtv28β€’9mo ago
ohh okay
NNKtv28
NNKtv28β€’9mo ago
Heyyy i got progress
No description
NNKtv28
NNKtv28β€’9mo ago
i commented the 1 line you told me and now the ping button works πŸ˜„
duck
duckβ€’9mo ago
I didn't tell you to comment any lines, but ok
NNKtv28
NNKtv28β€’9mo ago
ik but i tryed it and it worked perfectly cause tecnically the button interaction is not a command interaction so it made sense in my head to remove it
duck
duckβ€’9mo ago
on the assumption the line you're referring to was your typeguard, I can only assume this is further straying from the advice you've been given
NNKtv28
NNKtv28β€’9mo ago
alright then my brain is not braining, ima head to bed and hope i can get it right tomorrow cause i understood that the line
//if (!interaction.isCommand()) return;
//if (!interaction.isCommand()) return;
was the one stopping the button interactions cause they werent command interactions and due to that the button interaction wasnt going through
duck
duckβ€’9mo ago
rest is important, so I leave this explanation for when you wake up: this isn't just a "this is the problem code so you should remove it" situation you do want to prevent component interactions from being handled as command interactions however the same applies for the other way around: you don't want command interactions from being handled as component interactions therefore typeguarding is still important, it just needs to be handled differently than simply returning on the first line
NNKtv28
NNKtv28β€’9mo ago
ima continue with other commands and leave the ticket thing for when i finish the commands cause i dont want to spend more time than i need to on a single command i got 2 weeks to finish this bot or im screwed pls dont delete this channel cause i will need it in the future withon 2 weeks
treble/luna
treble/lunaβ€’9mo ago
why take on a deadline if you cant handle it?
NNKtv28
NNKtv28β€’9mo ago
cause i can take it, and thats the only command thats giving me issues the rest of the commands work fine + the ticket thing is optional and i wanted to add it as an extra for the client