Unknown Interaction on interaction.reply()

The error is in the given picture, im using discord.js v14, i don't know why this is happening Code:
import {
SlashCommandBuilder,
PermissionFlagsBits,
EmbedBuilder,
} from 'discord.js';
import { command, query } from '../utils/index.js';

export default command(
new SlashCommandBuilder()
.setName('createorder')
.setDescription('Add an order to the current queue')
// Too many chars in the message, so i removed this in the message
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
async (interaction) => {
const userId = interaction.user.id as string;

if (
userId !== '1151874231429242911' &&
userId !== '1151534189729034343'
) {
await interaction.deferReply();
return await interaction.reply({
content: "You're not allowed to use this command",
ephemeral: true,
});
}

const args = {
user: interaction.options.getUser('user', true)!.id,
product: interaction.options.getString('product', true),
paid: interaction.options.getString('paid', true),
status: interaction.options.getString('status', true),
price: interaction.options.getString('price', true),
channel: interaction.options.getChannel('channel')?.id ?? '🚫',
payment: interaction.options.getString('payment') ?? '🚫',
};

for (const arg in args) {
if (args[arg as keyof typeof args] === null) {
await interaction.deferReply();
return await interaction.reply({
content: 'Something went wrong.',
ephemeral: true,
});
}
}

const { insertId } = (await query(
'INSERT INTO orders (user, product, paid, status, price, channel, payment) VALUES (?, ?, ?, ?, ?, ?, ?)',
Object.values(args),
)) as { insertId: number };

const embed = new EmbedBuilder()
.setColor('#ffffff')
.setTitle(`Order Information | No: ${insertId}`)
.addFields([
{
name: 'User:',
value: `<@${args.user}>`,
inline: true,
},
{
name: 'Channel:',
value:
args.channel.length > 17 ? `<#${args.channel}>` : '🚫',
inline: true,
},
{
name: 'Product:',
value: args.product as string,
inline: true,
},
{
name: 'Price:',
value: args.price as string,
inline: true,
},
{
name: 'Payment:',
value: args.payment as string,
inline: true,
},
{
name: 'Paid:',
value: args.paid as string,
inline: true,
},
{
name: 'Status:',
value: args.status as string,
inline: false,
},
]);

await interaction.deferReply();
await interaction.reply({
content: 'Order created:',
embeds: [embed],
});
},
);
import {
SlashCommandBuilder,
PermissionFlagsBits,
EmbedBuilder,
} from 'discord.js';
import { command, query } from '../utils/index.js';

export default command(
new SlashCommandBuilder()
.setName('createorder')
.setDescription('Add an order to the current queue')
// Too many chars in the message, so i removed this in the message
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
async (interaction) => {
const userId = interaction.user.id as string;

if (
userId !== '1151874231429242911' &&
userId !== '1151534189729034343'
) {
await interaction.deferReply();
return await interaction.reply({
content: "You're not allowed to use this command",
ephemeral: true,
});
}

const args = {
user: interaction.options.getUser('user', true)!.id,
product: interaction.options.getString('product', true),
paid: interaction.options.getString('paid', true),
status: interaction.options.getString('status', true),
price: interaction.options.getString('price', true),
channel: interaction.options.getChannel('channel')?.id ?? '🚫',
payment: interaction.options.getString('payment') ?? '🚫',
};

for (const arg in args) {
if (args[arg as keyof typeof args] === null) {
await interaction.deferReply();
return await interaction.reply({
content: 'Something went wrong.',
ephemeral: true,
});
}
}

const { insertId } = (await query(
'INSERT INTO orders (user, product, paid, status, price, channel, payment) VALUES (?, ?, ?, ?, ?, ?, ?)',
Object.values(args),
)) as { insertId: number };

const embed = new EmbedBuilder()
.setColor('#ffffff')
.setTitle(`Order Information | No: ${insertId}`)
.addFields([
{
name: 'User:',
value: `<@${args.user}>`,
inline: true,
},
{
name: 'Channel:',
value:
args.channel.length > 17 ? `<#${args.channel}>` : '🚫',
inline: true,
},
{
name: 'Product:',
value: args.product as string,
inline: true,
},
{
name: 'Price:',
value: args.price as string,
inline: true,
},
{
name: 'Payment:',
value: args.payment as string,
inline: true,
},
{
name: 'Paid:',
value: args.paid as string,
inline: true,
},
{
name: 'Status:',
value: args.status as string,
inline: false,
},
]);

await interaction.deferReply();
await interaction.reply({
content: 'Order created:',
embeds: [embed],
});
},
);
No description
12 Replies
d.js toolkit
d.js toolkit•7mo 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!
xx_lavaboy_xx123
xx_lavaboy_xx123•7mo ago
you need to use deferReply before doing the asynchronous tasks not right before replying and after u use deferReply u have to use editReply or followUp since deferring is actually a reply and u can't reply twice to a single interaction
ardelan
ardelan•7mo ago
i only reply once, should i defer before every asynchronous task, or just before the first?
xx_lavaboy_xx123
xx_lavaboy_xx123•7mo ago
before the first the deferReply method sends an initial reply just like the reply method and since you can only reply once you can't use deferReply multiple times
ardelan
ardelan•7mo ago
can i use interaction.deferred to make sure im not doing it multiple times?
xx_lavaboy_xx123
xx_lavaboy_xx123•7mo ago
yep
ardelan
ardelan•7mo ago
i'll test it, can i let you know if i still get errors? thank you in advance <3
xx_lavaboy_xx123
xx_lavaboy_xx123•7mo ago
yep
ardelan
ardelan•7mo ago
thank you i should only use .deferReply before async stuff, not right before the reply, right?
xx_lavaboy_xx123
xx_lavaboy_xx123•7mo ago
yep if you don't do anything asynchronous then you can just use reply
ardelan
ardelan•7mo ago
understood, thx
ardelan
ardelan•7mo ago
hey, sry for bothering, but do u know why this is happening
No description