Reputation: 102
When I clicked the button, he appeared "This interaction failed" but it has the function I want to do, and I don't know why the error occurred.
Function: I want to make a private channel after clicking the button
Question: I can’t stop him from showing "This interaction failed" ,Except for this error, there is no problem, even the function works normally
const {
MessageActionRow,
MessageButton,
Interaction,
Permissions,
DiscordAPIError,
discord
} = require('discord.js');
const {
MessageEmbed
} = require('discord.js')
const client = require('../index')
const config = require("../config.json");
const { intersection } = require('lodash');
client.on("interactionCreate", async (interaction) => {
if (interaction.isButton()) {
if (interaction.customId === 'tic') {
if(!client.channels.cache.find(channel => channel.name === interaction.user.username+"-test")){
let channelName = interaction.user.username+"-test";
interaction.guild.channels.create(channelName, {
type: "text",
parent: config.categoryId,
permissionOverwrites: [
{
id: '887160123733184533', //To make it be seen by a certain role, user an ID instead
allow: [Permissions.FLAGS.VIEW_CHANNEL, Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.READ_MESSAGE_HISTORY], //Allow permissions
deny: [Permissions.FLAGS.CREATE_INSTANT_INVITE] //Deny permissions
},{
id: '759286092548538388', //To make it be seen by a certain role, user an ID instead
deny: [Permissions.FLAGS.VIEW_CHANNEL] //Deny permissions
},{
id: interaction.user.id,
allow: [Permissions.FLAGS.VIEW_CHANNEL, Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.READ_MESSAGE_HISTORY], //Allow permissions
deny: [Permissions.FLAGS.CREATE_INSTANT_INVITE] //Deny permissions
}
]
})
const del = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('del')
.setLabel('🗑️ delete!')
.setStyle('DANGER'),
);
const welcome = new MessageEmbed()
.setTitle("test")
.setDescription("test\n:warning: __**error**__: warn!!!")
.setColor("#FF5809")
setTimeout(() => {
const channel123 = client.channels.cache.find(channel => channel.name === interaction.user.username+"-test");
channel123.send({
embeds: [welcome],
components: [del]
})
let a = new MessageEmbed()
.setTitle("__**test**__")
.setColor("#00DB00")
.setDescription(":white_check_mark: test!")
interaction.user.send({embeds: [a] });
}, 500)
}else{
const warn = new MessageEmbed()
.setColor("RED")
.setTitle("__**test**__")
.setDescription(":warning: error!")
interaction.user.send({embeds: [warn] })
}
}
}})
If you can tell me the solution, I am very grateful to you
Upvotes: 0
Views: 923
Reputation: 683
That's because you never actually responded to the interaction. First, defer the reply using interaction.deferReply(), this will show a "Bot is thinking" message to the command user. Afterwards, when everything has been done, you reply to it with interaction.editReply().
Upvotes: 1