This question already has answers here:
Discord.js: DiscordAPIError[40060]: Interaction has already been acknowledged
(2 answers)
Closed 26 days ago.
I cannot reply to a reaction if the user has already reported the message.
I get this error:
Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred.
My Code:
Note: I have all modules imported, this code is a snippet of the file.
let reported = [];
collector.on("collect", async interaction => {
if (interaction.user.id === message.author.id) {
// this message works
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.error} You cannot report yourself!`)
await interaction.reply({ embeds: [error], ephemeral: true });
return;
}
await interaction.deferUpdate();
if (interaction.customId === `report - ${message.id} `) {
if (reported.includes(interaction.user.id)) {
// this message doesnt send
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.error} You have already reported this message!`)
await interaction.reply({ embeds: [error], ephemeral: true });
return;
}
reported.push(interaction.user.id);
const reportChannel = await client.channels.cache.get("channel_id");
// this message works
const report = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setAuthor({ name: message.author.tag, iconURL: message.author.displayAvatarURL({ format: "png", dynamic: true }), url: `https://discord.com/users/${message.author.id}` })
.setDescription(message.content)
.setFooter({ text: `Reported by: ${interaction.user.tag}`, iconURL: interaction.user.displayAvatarURL({ format: "png", dynamic: true }), url: `https://discord.com/users/${interaction.user.id}` })
const jumpBtn = new Discord.ActionRowBuilder()
.addComponents(
new Discord.ButtonBuilder()
.setStyle(Discord.ButtonStyle.Link)
.setLabel("Jump to Message")
.setURL(message.url)
)
reportChannel.send({ embeds: [report], components: [jumpBtn] });
}
})
I was expecting when the message is reported once it adds it to the array which it does, but then if they try report it again it sends hidden message saying they cannot.
You can't respond to the same interaction more than once. (AKA calling deferUpdate(), reply(), etc).
After the line await interaction.deferUpdate();, you can use interaction.editReply() instead of interaction.reply() to respond to the command.
docs
Related
im trying to get back all the license that exist in the json file the code below works fine
in the Console.Log. There im getting exactly what i need. but when i want to use it as a
.SetDescription i get nothing just empty space.
client.on('messageCreate', async (message) => {
if (message.content === '!acglobalbans') {
const res = await fetch('website');
const data = await res.json();
const licenses = data.globalbans.map(ban => ban.license);
console.log(licenses);
const embed = new MessageEmbed()
.setAuthor({ name: client.user.username, iconURL: client.user.displayAvatarURL() })
.setDescription("test: ", licenses)
.setColor("BLACK");
message.reply({ embeds: [embed] });
}
});
Hello I made a mail command which would take message from modal and send it to a mentioned user but it gives this error in modal window and does not log anything in console
const { Permissions } = require('discord.js');
const { Modal, TextInputComponent, showModal } = require('discord-modals')
const { Formatters } = require('discord.js');
module.exports.run = async (Client, message, args, prefix) => {
let member = message.mentions.members.first();
if(!message.content.includes(member)) {
embed = new MessageEmbed()
.setColor('RED')
.setTitle('Whome shd I send this mail to bruh')
.setDescription('Please mention the user whome you want to deliver the message')
await message.reply({embeds:[embed]})
}
else {
msg = new MessageEmbed()
.setColor('GREEN')
.setTitle('its time to type your message to your friend')
.setDescription('Please type your subject and message as you do while composing a normal mail using gmail just click the button and fill the subject and the message in their respective fields')
const row = new MessageActionRow().addComponents(
new MessageButton()
.setCustomId('compose')
.setLabel('Fill up info and compose')
.setEmoji('📧')
.setStyle('SECONDARY')
);
const msg = await message.reply({embeds:[msg],components: [row]});
//defining intput text fields
let textinput = new TextInputComponent()
.setCustomId('textinput-customid')
.setLabel('Subject')
.setStyle('SHORT')
.setMinLength('1')
.setMaxLength('200')
.setPlaceholder('type your Subject here it can be anything in less than 200 words')
.setRequired(true)
let textinputl = new TextInputComponent()
.setCustomId('textinput-customidl')
.setLabel('Message')
.setStyle('LONG')
.setMinLength('1')
.setMaxLength('4000')
.setPlaceholder('type your message here it can be anything in less than 4000 words')
.setRequired(true)
//main modal
const modal = new Modal() // We create a Modal
.setCustomId('modal-customid')
.setTitle('Compose a mail')
.addComponents([ textinput, textinputl ])
Client.on('interactionCreate', (interaction) => {
if(interaction.isButton) {
if(interaction.customId === 'compose'){
showModal(modal, {
client: Client,
interaction: interaction
})
}
}
})
Client.on('modalSubmit', async (modal) => {
if(modal.customId === 'modal-customid'){
const subjectresponse = modal.getTextInputValue('textinput-customid')
const messageresponse = modal.getTextInputValue('textinput-customidl')
modal.followUp({ content: 'Done message delivered.' + Formatters.codeBlock('markdown', firstResponse), ephemeral: true })
const embed = new MessageEmbed()
.setTitle('You have a new mail')
.setDescription(`${message.author.username} has sent you an email`)
.addField('Subject:', `${subjectresponse}`, false)
.addField('Message:', `${messageresponse}`, false)
await message.reply({embeds:[embed]});
}
})
}
}
module.exports.help = {
name: 'mail',
aliases: []
}
this is the code please check it out and tell what is the error
on the git error page of this people were asking about it but I dint understand that
Have to make a lot of code changes, here is what the final result was below, basically the issue was that there were a lot of variances in the code and how the code was handled. Needed to add checks to the code to help it move along. Added the member id to the embed to help the bot get that id when it needed it later.
command.js file
const mentionedMember = message.mentions.members.first();
if (!mentionedMember || mentionedMember.user.bot) {
const embed = new MessageEmbed()
.setColor('RED')
.setTitle('Whom should I send this mail to bruh')
.setDescription('Please mention the user whom you want to deliver the message, no bots');
message.reply({
embeds: [embed],
});
setTimeout(() => {
message.delete();
}, 100);
} else {
const rickrollmsg = new MessageEmbed()
.setColor('GREEN')
.setTitle('its time to type your message to your friend')
.setDescription('Please type your subject and message as you do while composing a normal mail using gmail just click the button and fill the subject and the message in their respective fields')
.setFooter({
text: mentionedMember.id,
});
const row = new MessageActionRow().addComponents(
new MessageButton()
.setCustomId('compose')
.setLabel('Fill up info and compose')
.setEmoji('📧')
.setStyle('SECONDARY'),
);
message.reply({
embeds: [rickrollmsg],
components: [row],
});
setTimeout(() => {
message.delete();
}, 100);
}
interactionCreate button code
const textinput = new TextInputComponent()
.setCustomId('rickmail-subject')
.setLabel('Subject')
.setStyle('SHORT')
.setMinLength('1')
.setMaxLength('200')
.setPlaceholder('type your Subject here it can be anything in less than 200 words')
.setRequired(true);
const textinputl = new TextInputComponent()
.setCustomId('rickmail-message')
.setLabel('Message')
.setStyle('LONG')
.setMinLength('1')
.setMaxLength('4000')
.setPlaceholder('type your message here it can be anything in less than 4000 words')
.setRequired(true);
const modal = new Modal()
.setCustomId('rickmail')
.setTitle('Compose a rickmail')
.addComponents([textinput, textinputl]);
showModal(modal, {
client: client,
interaction: inter,
});
modalSubmit listener
const member = modal.guild.members.cache.get(modal.message.embeds[0].footer.text);
const subject = modal.getTextInputValue('rickmail-subject');
const message = modal.getTextInputValue('rickmail-message');
const embed = new MessageEmbed()
.setColor('RANDOM')
.setTitle(`${subject}`)
.setDescription(`${message}`)
.setImage('https://www.icegif.com/wp-content/uploads/rick-roll-icegif-5.gif')
.setFooter({
text: `Message Received ${new Date().toLocaleString()}`,
});
modal.message.delete();
member.send({
embeds: [embed],
});
return modal.followUp({
content: 'Rickmail sent',
ephemeral: true,
});
I wanted to make a command to make the bot return its connection status to the database, but I got an error and I am a little confused now.
RangeError [MESSAGE_CONTENT_TYPE]: Message content must be a non-empty string.
const { MessageEmbed } = require('discord.js');
const quick = require('quick.db');
module.exports = {
name: 'ping',
aliases: [],
description: 'Get bot ping.',
permissions: [],
async execute(message, client) {
const ping = await getDBPingData();
const messagePing = Date.now();
const msg = await message.channel.send('Loading...');
const endMessagePing = Date.now() - messagePing;
const embed = new MessageEmbed()
.setDescription(
`
Database ping data:
- Fetch ping: \`${ping.endGet}ms\`
- Wright ping: \`${ping.endWright}ms\`
- Avrage ping: \`${ping.avarage}ms\`
Message ping: \`${endMessagePing}ms\`
`
)
.setColor('GREEN')
.setTimestamp();
msg.edit({
content: '',
embed,
});
},
};
async function getDBPingData() {
// get the fetch data ping
const startGet = Date.now();
await quick.get('QR=.');
const endGet = Date.now() - startGet;
// get the wright data ping
const startWright = Date.now();
await quick.set('QR=.', Buffer.from(startWright.toString()).toString('base64'));
const endWright = Date.now() - startWright;
// avrage ping time
const avarage = (endGet + endWright) / 2;
try {
quick.delete('QR=.');
} catch (error) {}
return { endGet, endWright, avarage };
}
I am using discord.js v13, and the packages in use for this command are: discord.js and quick.db.
In v13, messages sent by bots now support up to 10 embeds. As a result, the embed option was removed and replaced with an embeds array, which must be in the options object, so your message edit should be msg.edit({ embeds: [embed] }).
If you also want to remove the previous text (Loading...), you need to add content: null as providing an empty string ('') as the content will throw a RangeError.
msg.edit({
content: null,
embeds: [embed],
});
Try this:
// only need to edit embed in an embeds array
msg.edit({ embeds: [embed] })
So I've just completed writing a ping.js, echo.js, guildMemberAdd.js, and guildMemberRemove.js and I'm moving on to writing a ban.js and kick.js and currently all slash commands work except the latest commands which is kick and ban. I keep getting the error that "The reply to this interaction has not been sent or deferred." and I have no idea how to find a solution to it. I originally had it written "return interaction.followUp" and I switched them all to "await interaction.followUp" hoping it'd be the solution the problem, but it seems like that wasn't it. I originally also had it written "run: async (interaction) => {" but then I get the error that "command.execute" is not a function so I switched it to "async execute (intereaction) {" I've also tried a couple of other things, but still can't seem to find a fix, does anyone have any idea on this? I'll leave my interactionCreate.js and kick.js below
interactionCreate.js
module.exports = {
name: "interactionCreate",
async execute(interaction) {
if (!interaction.isCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction);
} catch (err) {
if (err) console.error(err);
await interaction.reply({
content: "An error occured while executing that command.",
ephemeral: true
});
}
}
}
kick.js
const { SlashCommandBuilder } = require('#discordjs/builders');
const { MessageEmbed } = require("discord.js")
module.exports = {
data: new SlashCommandBuilder()
.setName("kick")
.setDescription("Allows the admin or owner to kick the member.")
.addUserOption((option) => option.setName('user').setDescription('The person who you want to kick').setRequired(true))
.addStringOption(option => option.setName('reason').setDescription('Reason to kick member').setRequired(true)),
async execute (interaction) {
if(!interaction.member.permissions.has("KICK_MEMBERS")) return interaction.followUp({ content: "You do not have the power to kick that member.", ephemeral: true })
const user = interaction.options.getUser('user')
const member = interaction.guild.members.cache.get(user.id) || await interaction.guild.members.fetch(user.id).catch(err => {})
if(!member) return interaction.followUp({ content: "😅 | Well this is awkward... I'm unable to get details related to given member.", ephemeral: true });
const reason = interaction.options.getString('reason')
if(!member.kickable || member.user.id === member.user.id)
await interaction.followUp({ content: "😡 | I am unable to kick this member", ephemeral: true });
if(interaction.member.roles.highest.position <= member.roles.highest.position)
await interaction.followUp({ content: 'This member has equal or higher power as you so I cannot kick them.', ephemeral: true })
const embed = new MessageEmbed()
.setDescription(`**${member.user.tag}** is kicked out from the cookout for \`${reason}\``)
.setColor("#5104DB")
.setFooter({ text: "Kick Member" })
.setTimestamp()
await interaction.reply(`You are kicked from **\`${interaction.guild.name}\`** for \`${reason}\``).catch(err => {})
member.kick();
await interaction.followUp({ embeds: [ embed ]})
}
}
The error comes from line 19 and 22
await interaction.followUp({ content: "😡 | I am unable to kick this member", ephemeral: true });
await interaction.followUp({ content: 'This member has equal or higher power as you so I cannot kick them.', ephemeral: true })
You attempt to followUp to an interaction, with no reply as the error message suggests. You can change this to reply as you do further down in the code, which will work.
Note: you will likely receive unexpected errors if you don't return or stop the code when the conditions above are met
I was creating a command for locking a channel and used the .updateOverwrite() method to do this. With the code below I was trying to check if the channel already has VIEW_CHANNEL set to false and therefore respond with an error message. However, even if the channel has already been locked, it still 'locks' it again and skips the check, this check only seems to get triggered when the channel is unlocked. Would there be some other way to check for the channel overwrites?
if (message.member.hasPermission('MANAGE_CHANNELS')) {
if (!message.guild.roles.everyone.permissions.has('VIEW_CHANNEL')) {
const errorEmbed = new Discord.MessageEmbed()
.setDescription(`❌ '${message.channel.name}' is already locked.`)
.setColor('RED');
message.channel.send(errorEmbed);
}
else{
message.channel.updateOverwrite(message.channel.guild.roles.everyone, { VIEW_CHANNEL: false }).then(() => {
const msgEmbed = new Discord.MessageEmbed()
.setDescription(`✅ '${message.channel.name}' has been locked.`)
.setColor('GREEN');
message.channel.send(msgEmbed);
});
}
}
else {
const warningEmbed = new Discord.MessageEmbed()
.setDescription('🔒 Sorry, you do not have sufficient permissions to do this.')
.setColor('YELLOW');
message.channel.send(warningEmbed);
}
You need to check the permissions for the channel, you're currently checking global role permissions. Here is the updated code:
if (message.member.hasPermission('MANAGE_CHANNELS')) {
if (!message.channel.permissionsFor(message.guild.roles.everyone).has('VIEW_CHANNEL')) {
const errorEmbed = new Discord.MessageEmbed()
.setDescription(`❌ '${message.channel.name}' is already locked.`)
.setColor('RED');
message.channel.send(errorEmbed);
}
else{
message.channel.updateOverwrite(message.channel.guild.roles.everyone, { VIEW_CHANNEL: false }).then(() => {
const msgEmbed = new Discord.MessageEmbed()
.setDescription(`✅ '${message.channel.name}' has been locked.`)
.setColor('GREEN');
message.channel.send(msgEmbed);
});
}
}
else {
const warningEmbed = new Discord.MessageEmbed()
.setDescription('🔒 Sorry, you do not have sufficient permissions to do this.')
.setColor('YELLOW');
message.channel.send(warningEmbed);
}