const ms = require('ms');
const { EmbedBuilder } = require('discord.js');
const { ApplicationCommandType, ApplicationCommandOptionType } = require('discord.js');
module.exports = {
name: 'guide',
description: 'A guide of everything you need to know!',
voiceChannel: false,
options: [
{
name: 'guide',
description: 'Select a guide to continue',
type: ApplicationCommandOptionType.String,
required: true,
choices: [
{
name: "data",
value: "guide_data"
},
{
name: "codebean",
value: "guide_code",
description: "A guide on CodeBean"
}
]
}
],
async execute({ inter }) {
const DataGuide = new EmbedBuilder()
.setColor('#5679EF')
.setAuthor({ name: client.user.username, iconURL: client.user.displayAvatarURL({ size: 1024, dynamic: true }) })
.setTitle('π° Guide')
.setDescription("How we use your data and how to prevent us from using your data")
.setFooter({ text: 'Powered by Nonay', iconURL: inter.member.avatarURL({ dynamic: true })});
const CodeBean = new EmbedBuilder()
.setColor('#5679EF')
.setAuthor({ name: client.user.username, iconURL: client.user.displayAvatarURL({ size: 1024, dynamic: true }) })
.setTitle('π° Guide')
.setDescription("code things")
.setFooter({ text: 'Powered by Nonay', iconURL: inter.member.avatarURL({ dynamic: true })});
const adata = inter.options.getChoice('guide_data');
const acode = inter.options.getChoice('guide_code');
switch (adata) {
case 'data':
await inter.reply({ embeds: [DataGuide] })
}
switch (acode) {
case 'codebean':
await inter.reply({ embeds: [CodeBean] })
}
},
};
Basically, what I am trying to do is provide people with a guide of what to do with my bot but I cant figure out how to use choices and how to respond to a certain choice that gets selected (for example, someone selects 'data' and gets a guide about their data)
Most of what you have typed in is correct actually. There's just two mistakes. When you declare choices for an option, you have to give it a name property and a value property. The name property tells what the choice would look like on the app and the value property is what you would receive if the user selected the option. You also seem to have misunderstood that choices are not another option by itself. It just gives a few hardcoded choices for the user to select from if the command had a string option. So, there isn't anything called as getChoice() So, your fixed code would look like this:
const ms = require('ms');
const { EmbedBuilder } = require('discord.js');
const { ApplicationCommandType, ApplicationCommandOptionType } = require('discord.js');
module.exports = {
name: 'guide',
description: 'A guide of everything you need to know!',
voiceChannel: false,
options: [
{
name: 'guide',
description: 'Select a guide to continue',
type: ApplicationCommandOptionType.String,
required: true,
choices: [
{
name: "data",
value: "guide_data"
},
{
name: "codebean",
value: "guide_code",
description: "A guide on CodeBean"
}
]
}
],
async execute({ inter }) {
const DataGuide = new EmbedBuilder()
.setColor('#5679EF')
.setAuthor({ name: client.user.username, iconURL: client.user.displayAvatarURL({ size: 1024, dynamic: true }) })
.setTitle('π° Guide')
.setDescription("How we use your data and how to prevent us from using your data")
.setFooter({ text: 'Powered by Nonay', iconURL: inter.member.avatarURL({ dynamic: true })});
const CodeBean = new EmbedBuilder()
.setColor('#5679EF')
.setAuthor({ name: client.user.username, iconURL: client.user.displayAvatarURL({ size: 1024, dynamic: true }) })
.setTitle('π° Guide')
.setDescription("code things")
.setFooter({ text: 'Powered by Nonay', iconURL: inter.member.avatarURL({ dynamic: true })});
const guide = inter.options.getString('guide'); // This gets whatever the user typed in for the guide option
switch (guide) {
case "guide_data":
await inter.reply({ embeds: [DataGuide] })
break;
case "guide_code":
await inter.reply({ embeds: [CodeBean] })
break;
}
},
};
Related
I have the following code that creates a slash command. I want the embed to be updated every 10 seconds.
const embed = new EmbedBuilder()
.setAuthor({ name: track.title, iconURL: client.user.displayAvatarURL({ size: 1024, dynamic: true }) })
.setThumbnail(track.thumbnail)
.addFields(
{ name: "**volume**", value: `**${queue.volume}**` },
{ name: "**Ψ§time**", value: `**${trackDuration}**` },
{ name: "**song**", value: `**${progress}**` },
{ name: "**repeat mode**", value: `**${methods[queue.repeatMode]}**` },
{ name: "**track**", value: `**${track.requestedBy}**` }
)
.setFooter({ text: inter.user.username, iconURL: inter.member.avatarURL({ dynamic: true }) })
.setColor("ff0000")
.setTimestamp();
I tried with setInterval but it didn't work.
You really need to add more information, but you could use setInterval().
I am just taking a guess on how you use your bot, interaction.editReply() is my guess that you send the embed as a reply, but you can change it to whatever you want, and the code within the setInterval will run once every 10 seconds.
EDIT: You also need to send the initial reply if you wish to edit it.
e.g.
const embed = new EmbedBuilder()
.setAuthor({ name: track.title, iconURL: client.user.displayAvatarURL({ size: 1024, dynamic: true }) })
.setThumbnail(track.thumbnail)
.addFields(
{ name: '**volume**', value: `**${queue.volume}**` },
{ name: '**Ψ§time**', value: `**${trackDuration}**` },
{ name: '**song**', value: `**${progress}**` },
{ name: '**repeat mode**', value: `**${methods[queue.repeatMode]}**` },
{ name: '**track**', value: `**${track.requestedBy}**` }
)
.setFooter({ text: inter.user.username, iconURL: inter.member.avatarURL({ dynamic: true }) })
.setColor('ff0000')
.setTimestamp();
// You need to send the initial embed if you wish to edit it
interaction.reply({ embeds: [embed] });
setInterval(() => {
// Code to run every 10 seconds:
interaction.editReply({ embeds: [embed] });
// 10 seconds in milliseconds
}, 10000);
I've been working to create a Purge Command in JavaScript based off this Purge Command written in TypeScript for reconlx's DJS v13 command handler (I modified a few bits to make all the handlers and whatnot function in DJS v14), however, there are some bugs and a few things I'm losing my mind over.
Firstly, everytime the command is enacted, this little nuisance of a message appears with the success confirmation embeds, and I don't really know how to deal with it.
Secondly, when I purge specifically by user and term, the wrong embed is sent and my bot will purge as normal. According to the source code, it (referring to my bot) should be sending the cleanPurge embed, but it instead sends the userPurge embed. Purging specifically by user works as intended, just with the annoying "thinking" message as an unwanted bonus.
Thirdly, when purging by term, I can only purge if I enact the command right after a message with the specified term. Here's an example (if you don't understand my wording).
// It is okay to purge during these situations
// cat in a hat
// cat in a hat
// cat in a hat
// /purge [amount: 3] {term: cat}
// The command will purge only if it is enacted right after the message with the specific term, however...
// The command won't purge during these situations
// cat in a hat
// cat in a hat
// cat in a hat
// SHITPOST
// /purge [amount: 3] {term: cat}
// The message "SHITPOST" is in-between the last message with the term "cat" and when I enact my command,
// therefore, for some reason, I can't purge any messages with my specified keyword before the message "SHITPOST".
// I can purge messages with the term "cat" AFTER the message "SHITPOST" until another message gets in the way.
// If you have no idea what I mean, a link to my bot's demo is below.
Purging without specifics DOESN'T bring up the "{Bot} is thinking..." message and works as intended.
If you're confused, here's a link to a demo of my bot's bugs
Any questions, please feel free to ask me, and sorry if my wording is shit.
Source code for purge.js
const { EmbedBuilder, ApplicationCommandOptionType, PermissionsBitField } = require("discord.js");
const { Command } = require("reconlx");
const ms = require("ms");
module.exports = new Command({
name: "purge",
description: "Deletes a specified number of messages",
userPermissions: PermissionsBitField.Flags.ManageMessages,
options: [
{
name: "amount",
description: "Number of messages to purge",
type: ApplicationCommandOptionType.Integer,
min_value: 1,
max_value: 100,
required: true,
},
{
name: "user",
description: "Purge this member's messages",
type: ApplicationCommandOptionType.User,
required: false,
},
{
name: "term",
description: "Purge messages with this specific term",
type: ApplicationCommandOptionType.String,
required: false,
},
{
name: "reason",
description: "Reason for purging",
type: ApplicationCommandOptionType.String,
required: false,
},
],
run: async ({ interaction }) => {
const amount = interaction.options.getInteger("amount");
const user = interaction.options.getUser("user");
const term = interaction.options.getString("term");
const reason = interaction.options.getString("reason") || "Unspecified";
const channel = interaction.channel
const messages = await interaction.channel.messages.fetch({
limit: amount + 1,
});
if (user) {
const userMessages = messages.filter((m) => m.author.id === user.id);
const purged = await interaction.channel.bulkDelete(userMessages, true);
const userPurge = new EmbedBuilder()
.setColor("#2F3136")
.setTitle(`π§Ή PURGED!`)
.addFields(
{
name: `Cleared ${purged.size} message${
purged.size > 1 ? "s" : ""
}!`,
value: `Any messages from \`${user.tag}\` have been deleted from ${channel}!`
},
{
name: `User`,
value: `\`${user.tag}\``,
inline: true
},
{
name: `Term`,
value: `\`Unspecified\``,
inline: true
},
{
name: `Reason(s)`,
value: `\`${reason}\``,
inline: true
},
)
interaction.channel.send({ embeds: [userPurge] });
} else if (term) {
const filteredTerm = messages.filter((m) =>
m.content.toLowerCase().includes(term)
);
const purged = await interaction.channel.bulkDelete(filteredTerm, true);
const termPurge = new EmbedBuilder()
.setColor("#2F3136")
.setTitle(`π§Ή PURGED!`)
.addFields(
{
name: `Cleared ${purged.size} message${
purged.size > 1 ? "s" : ""
}!`,
value: `Any messages with the term ||\`${term}\`|| have been deleted from ${channel}!`
},
{
name: `User`,
value: `\`Unspecified\``,
inline: true
},
{
name: `Term`,
value: `||\`${term}\`||`,
inline: true
},
{
name: `Reason(s)`,
value: `\`${reason}\``,
inline: true
},
)
interaction.channel.send({ embeds: [termPurge] });
} else if (term && user) {
const memberMessages = messages.filter((m) => m.author.id === member.id && m.content.toLowerCase().includes(term));
const purged = await interaction.channel.bulkDelete(memberMessages, true);
const cleanPurge = new EmbedBuilder()
.setColor("#2F3136")
.setTitle(`π§Ή PURGED!`)
.addFields(
{
name: `Cleared ${purged.size} message${
purged.size > 1 ? "s" : ""
}!`,
value: `Any messages from \`${user.tag}\` with the term ||\`${term}\`|| have been deleted from ${channel}!`
},
{
name: `User`,
value: `\`${user.tag}\``,
inline: true
},
{
name: `Term`,
value: `||\`${term}\`||`,
inline: true
},
{
name: `Reason(s)`,
value: `\`${reason}\``,
inline: true
},
)
interaction.channel.send({ embeds: [cleanPurge] });
} else {
const purged = await interaction.channel.bulkDelete(messages, true);
const purge = new EmbedBuilder()
.setColor("#2F3136")
.setTitle(`π§Ή PURGED!`)
.addFields(
{
name: `Cleared ${purged.size - 1} message${
purged.size > 1 ? "s" : ""
}!`,
value: `The specified number of messages have been deleted from ${channel}!`
},
{
name: `User`,
value: `\`Unspecified\``,
inline: true
},
{
name: `Term`,
value: `\`Unspecified\``,
inline: true
},
{
name: `Reason(s)`,
value: `\`Unspecified\``,
inline: true
},
)
interaction.channel.send({ embeds: [purge] });
}
},
});
Your video is still processing, so I couldn't watch it, but:
In the "cat"/"cat"/"cat"/"shitpost" situation, you'd need amount=4, because you're only fetching N + 1 messages. If you need want your bot to purge N last matching messages even if there are more in between (e.g. in a "a"/"b"/"a"/"b"/"a"/"b" situation where you want to purge all "b"s), you'd need to fetch more messages until you've purged enough. Another "good enough" option might be to fetch e.g. amount * 2 messages and hope it's enough.
In any case, you could start by de-quadriplicating your message filtering and embed building:
{
run: async ({ interaction }) => {
const { options, channel } = interaction;
const amount = options.getInteger("amount");
const user = options.getUser("user");
const term = options.getString("term");
const reason = options.getString("reason") || "Unspecified";
const lastNMessages = await channel.messages.fetch({
limit: amount + 1,
});
const filteredMessages = lastNMessages.filter((message) => {
if (user && message.author.id !== user.id) {
return false;
}
if (term && !message.content.toLowerCase().includes(term)) {
return false;
}
return true;
});
const purged = await channel.bulkDelete(filteredMessages, true);
const title = `Cleared ${purged.size} message${purged.size > 1 ? "s" : ""}!`;
const message = [
`${purged.size} messages`,
user ? ` from \`${user.tag}\`` : "",
term ? ` containing \`${term}\`` : "",
` have been deleted from ${channel}!`,
].join("");
const userPurge = new EmbedBuilder()
.setColor("#2F3136")
.setTitle(`π§Ή PURGED!`)
.addFields(
{
name: title,
value: message,
},
{
name: `User`,
value: user ? `\`${user.tag}\`` : "Unspecified",
inline: true,
},
{
name: `Term`,
value: term ? `||\`${term}\`||` : `\`Unspecified\``,
inline: true,
},
{
name: `Reason(s)`,
value: `\`${reason}\``,
inline: true,
},
);
await channel.send({ embeds: [userPurge] });
},
}
I was coding a userInfo command but when I use the command, the joinedAtTimeStamp is showing <t:NaN:R> in the embed. It's the only problem in this code.
My code:
const { MessageEmbed, ContextMenuInteraction } = require("discord.js");
module.exports = {
name: "userInfo",
aliases: ["user"],
permissions: ["SEND_MESSAGES", "ATTACH_FILES"],
description: "user",
async execute(message, args, cmd, client, Discord, profileData) {
const target = message.mentions.users.first();
if(!args[0]) {
const response2 = new MessageEmbed()
.setColor("RANDOM")
.setAuthor({name: message.author.tag, iconURL: message.author.displayAvatarURL({dynamic: true})})
.setThumbnail(message.author.displayAvatarURL({dynamic: true}))
.addFields(
{name: "ID", value: message.author.id},
{name: "Joined Server", value: `<t:${parseInt(message.author.joinedTimestamp / 1000)}:R>`, inline: true},
{name: "Account Created", value: `<t:${parseInt(message.author.createdTimestamp / 1000)}:R>`, inline: true},
);
message.reply({embeds:[response2]});
}
const response = new MessageEmbed()
.setColor("RANDOM")
.setAuthor({name: target.tag, iconURL: target.displayAvatarURL({dynamic: true})})
.setThumbnail(target.displayAvatarURL({dynamic: true}))
.addFields(
{name: "ID", value: target.id},
{name: "Joined Server", value: `<t:${parseInt(target.joinedTimestamp / 1000)}:R>`, inline: true},
{name: "Account Created", value: `<t:${parseInt(target.createdTimestamp / 1000)}:R>`, inline: true},
);
message.reply({embeds: [response], ephemeral: true})
}
}
I am using discord.js v13 and node 16.
message.author is a User and it doesn't have a joinedTimestamp property, only GuildMembers have. message.member represents the author of the message as a guild member, so you can use that as it will have a joinedTimestamp property.
The reason you see NaN instead of the correct value is because parseInt will return NaN if you try to parse undefined:
console.log('undefined:', parseInt(undefined / 1000, 10));
console.log('3459192421512:', parseInt(3459192421512 / 1000, 10));
The following code should work as expected
.addFields(
{ name: 'ID', value: message.author.id },
{
name: 'Joined Server',
value: `<t:${parseInt(message.member.joinedTimestamp / 1000, 10)}:R>`,
inline: true,
},
{
name: 'Account Created',
value: `<t:${parseInt(message.author.createdTimestamp / 1000, 10)}:R>`,
inline: true,
},
);
As for target, it's the same issue; message.mentions.users.first() is a User. You could create a new variable, e.g. targetMember and assign message.mentions.members.first(), so it will be a GuildMember:
const target = message.mentions.users.first();
const targetMember = message.mentions.members.first();
And then, just replace target:
.addFields(
{ name: 'ID', value: target.id },
{
name: 'Joined Server',
value: `<t:${parseInt(targetMember.joinedTimestamp / 1000, 10)}:R>`,
inline: true,
},
{
name: 'Account Created',
value: `<t:${parseInt(target.createdTimestamp / 1000, 10)}:R>`,
inline: true,
},
);
PS: It's a good idea to use the radix in parseInt. That's why I added 10 as the second parameter in parseInt.
Could you verify the type of target.joinedTimestamp?
It could be that the double conversion you are doing here:
parseInt(target.joinedTimestamp / 1000)
destroyed your number.
(You are converting whatever target.createdTimestamp is to number, dividing it by 100 (making it a floating point number) and then discarding the floating point by converting back to int.)
Hey so I have this error in my Schema and I don't know how to fix it. I also tried looking at the other files, but couldn't find any issue. Can someone help me fix this issue, please? I would really be appreciated.
There are 5 different suggestion files I have made
Schema 1:
const { model, Schema } = require('mongoose');
module.exports = model("suggestDB", new Schema({
GuildID: String,
MessageID: String,
Details: Array,
MemberID: String,
DM: Boolean,
}));
Schema 2:
const { model, Schema } = require('mongoose');
module.exports = model("suggestSetupDB", new Schema({
GuildID: String,
ChannelID: String,
}))
suggest.js file:
const { CommandInteraction, MessageEmbed, MessageActionRow, MessageButton } = require("discord.js");
const suggestDB = require("../../Structures/Schemas/suggestDB");
const suggestSetupDB = require("../../Structures/Schemas/suggestSetupDB");
module.exports = {
name: "suggest",
description: "Create a suggestion.",
usage: "/suggest",
disabled: false,
botCommandChannelOnly: true,
options: [
{
name: "type",
description: "Select a type.",
required: true,
type: "STRING",
choices: [
{
name: "Command",
value: "Command",
},
{
name: "Event",
value: "Event",
},
{
name: "System",
value: "System",
},
{
name: "Other",
value: "Other",
},
],
},
{
name: "suggestion",
description: "Describe your suggestion.",
type: "STRING",
required: true,
},
{
name: "dm",
description: "Set whether the bot will DM you, once your suggestion has been declined or accepted.",
type: "BOOLEAN",
required: true,
}
],
/**
*
* #param {CommandInteraction} interaction
*/
async execute(interaction, client) {
const { options, guildId, member, user } = interaction;
const suggestionsSetup = await suggestSetupDB.findOne({ GuildID: guildId });
var suggestionsChannel;
if(!suggestionsSetup) {
return interaction.reply({embeds: [new MessageEmbed().setColor("RED").setDescription(`β This server has not setup the suggestion system.`)]})
} else {
suggestionsChannel = interaction.guild.channels.cache.get(suggestionsSetup.ChannelID)
}
const type = options.getString("type");
const suggestion = options.getString("suggestion");
const DM = options.getBoolean("dm")
const Embed = new MessageEmbed()
.setColor(system_embed_colour)
.setAuthor({name: `${user.tag}`, iconURL: `${user.displayAvatarURL({dynamic: true})}`}, )
.setDescription(`**Suggestion:**\n${suggestion}`)
.addFields(
{name: "Type", value: type, inline: true},
{name: "Status", value: "π Pending", inline: true},
{name: "Reason", value: "Pending", inline: true},
)
try {
const M = await suggestionsChannel.send({embeds: [Embed]});
M.react("π");
M.react("π");
await suggestDB.create({GuildID: guildId, MessageID: M.id, Details: [
{
MemberID: member.id,
Type: type,
Suggestion: suggestion,
}],
MemberID: member.id,
DM: DM
})
interaction.reply({embeds: [new MessageEmbed().setColor(system_embed_colour).setDescription(`β
Your [suggestion](${M.url}) was successfully created and sent to ${suggestionsChannel}`).setFooter({text: "This system was created by M4HD1#6336"})], ephemeral: true})
} catch (err) {
console.log(err);
return interaction.reply({embeds: [new MessageEmbed().setColor("RED").setDescription(`β An error occured.`)]})
}
}
}
suggest-setup file:
const { MessageEmbed, Message, CommandInteraction, Client } = require("discord.js");
const DB = require("../../Structures/Schemas/suggestSetupDB");
module.exports = {
name: "suggest-setup",
description: "Set up the channel to where suggestions are sent.",
usage: "/suggest-setup",
permission: "ADMINISTRATOR",
options: [
{
name: "set",
description: "Set the channel where suggestions will be sent.",
type: "SUB_COMMAND",
options: [
{name: "channel", description: "The channel where suggestions will be sent.", type: "CHANNEL", channelTypes: ["GUILD_TEXT"], required: true}
]
},
{
name: "current-channel",
description: "Display the current suggestions channel.",
type: "SUB_COMMAND",
},
],
/**
*
* #param {CommandInteraction} interaction
* #param {Client} client
*/
async execute(interaction, client) {
switch(interaction.options.getSubcommand()) {
case "set":
const channel = interaction.options.getChannel("channel");
try {
await channel.send({embeds: [new MessageEmbed().setColor("AQUA").setDescription(`β
This channel has been set as a suggestions channel.`)]}).then(async() => {
await DB.findOneAndUpdate({GuildID: interaction.guild.id}, {ChannelID: channel.id}, {new: true, upsert: true})
interaction.reply({embeds: [new MessageEmbed().setColor(admin_embed_colour).setDescription(`β
${channel} has successfully been set as the suggestions channel for ${interaction.guild.name}.`)]})
})
} catch (error) {
if(error.message === "Missing Access") {
return interaction.reply({embeds: [new MessageEmbed().setColor("RED").setDescription(`β The bot does not have access to this channel.`)]})
} else {
return interaction.reply({embeds: [new MessageEmbed().setColor("RED").setDescription(`${client.emojisObj.animated_cross} An error occured. \n\n \`\`\`${error}\`\`\``).setFooter({text: "This system was created by M4HD1#6336"})]})
}
}
break;
case "current-channel":
const suggestion = await DB.findOne({GuildID: interaction.guild.id})
if(!suggestion)
return interaction.reply({embeds: [new MessageEmbed().setColor("RED").setDescription(`β This server has not setup the suggestion system.`)]})
return interaction.reply({embeds: [new MessageEmbed().setColor("AQUA").setDescription(`The suggestions channel is currently set to <#${suggestion.ChannelID}>`)]})
break;
}
},
};
suggestion.js:
const { MessageEmbed, Message, CommandInteraction, Client } = require("discord.js");
const suggestSetupDB = require("../../Structures/Schemas/suggestSetupDB");
const suggestDB = require("../../Structures/Schemas/suggestDB");
module.exports = {
name: "suggestion",
description: "Set up the channel to where suggestions are sent.",
usage: "/suggestion",
permission: "ADMINISTRATOR",
options: [
{
name: "accept",
description: "Accept a suggestion.",
type: "SUB_COMMAND",
options: [
{name: "message-id", description: "The message id of the suggestion you want to accept.", type: "STRING", required: true},
{name: "reason", description: "The reason why this suggestion was accepted.", type: "STRING", required: true}
]
},
{
name: "decline",
description: "Decline a suggestion.",
type: "SUB_COMMAND",
options: [
{name: "message-id", description: "The message id of the suggestion you want to decline.", type: "STRING", required: true},
{name: "reason", description: "The reason why this suggestion was declined.", type: "STRING", required: true}
]
},
],
/**
*
* #param {CommandInteraction} interaction
* #param {Client} client
*/
async execute(interaction, client) {
const messageId = interaction.options.getString("message-id");
const reason = interaction.options.getString("reason");
const suggestionsSetup = await suggestSetupDB.findOne({ GuildID: interaction.guildId });
var suggestionsChannel;
if(!suggestionsSetup) {
return interaction.reply({embeds: [new MessageEmbed().setColor("RED").setDescription(`β This server has not setup the suggestion system.`)]})
} else {
suggestionsChannel = interaction.guild.channels.cache.get(suggestionsSetup.ChannelID)
}
const suggestion = await suggestDB.findOne({GuildID: interaction.guild.id, MessageID: messageId})
if(!suggestion)
return interaction.reply({embeds: [new MessageEmbed().setColor("RED").setDescription(`β This suggestion was not found in the database.`)]})
const message = await suggestionsChannel.messages.fetch(messageId)
if(!message)
return interaction.reply({embeds: [new MessageEmbed().setColor("RED").setDescription(`β This message was not found.`)]})
const Embed = message.embeds[0];
if(!Embed) return;
switch(interaction.options.getSubcommand()) {
case "accept":
Embed.fields[1] = {name: "Status", value: "Accepted", inline: true};
Embed.fields[2] = {name: "Reason", value: `${reason}`, inline: true}
message.edit({embeds: [Embed.setColor("GREEN")], content: `<#${suggestion.MemberID}>`});
if(suggestion.DM) {
const member = client.users.cache.get(suggestion.MemberID);
member.send({embeds: [new MessageEmbed().setColor("GREEN").setTitle("Suggestion π‘").setDescription(`Your suggestion was accepted β
`).addFields({name: "Suggestion", value: `[link](${message.url})`, inline: true}, {name: "Guild", value: `${interaction.guild.name}`, inline: true}, {name: "Reason", value: `${reason}`, inline: true})]}).catch(() => null)
}
return interaction.reply({embeds: [new MessageEmbed().setColor("AQUA").setDescription(`[Suggestion](${message.url}) was accepted β
`)], ephemeral: true})
break;
case "decline":
Embed.fields[1] = {name: "Status", value: "Declined", inline: true};
Embed.fields[2] = {name: "Reason", value: `${reason}`, inline: true}
message.edit({embeds: [Embed.setColor("RED")], content: `<#${suggestion.MemberID}>`});
if(suggestion.DM) {
const member = client.users.cache.get(suggestion.MemberID);
member.send({embeds: [new MessageEmbed().setColor("RED").setTitle("Suggestion π‘").setDescription(`Your suggestion was declined. β
`).addFields({name: "Suggestion", value: `[link](${message.url})`, inline: true}, {name: "Guild", value: `${interaction.guild.name}`, inline: true}, {name: "Reason", value: `${reason}`, inline: true})]}).catch(() => null)
}
return interaction.reply({embeds: [new MessageEmbed().setColor("AQUA").setDescription(`[Suggestion](${message.url}) declined β
`)], ephemeral: true})
break;
}
},
};
And this is the error I get:
/Users/Aplex/Documents/Aplel/node_modules/mongoose/lib/index.js:505
throw new _mongoose.Error.OverwriteModelError(name);
^
OverwriteModelError: Cannot overwrite `suggestDB` model once compiled.
at Mongoose.model (/Users/Aplex/Documents/Aplel/node_modules/mongoose/lib/index.js:505:13)
at Object.<anonymous> (/Users/Aplex/Documents/Aplel/Structures/Schemas/suggestDB.js:3:18)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1151:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/Aplex/Documents/Aplel/Commands/Moderation/suggest.js:2:19)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
Can someone help me find the issue in here?
This Worked for me
const { model, Schema, models } = require('mongoose');
module.exports = models.suggestDB || model("suggestDB", new Schema({
GuildID: String,
MessageID: String,
Details: Array,
MemberID: String,
DM: Boolean,
}));
faced this error in nextjs.
Hope This Helps
So I am building my bot using discord.js (v13).
Here is my code:
const { MessageEmbed } = require('discord.js')
const { SlashCommandBuilder } = require("#discordjs/builders")
const guild = require('../config.json');
module.exports = {
data: new SlashCommandBuilder()
.setName('server')
.setDescription('Display info about this server.'),
async execute(interaction) {
const exampleEmbed = new MessageEmbed()
.setColor('#0099ff')
.setTitle(`Server infomation on ${guild.name}`)
.setDescription('Tells Server Info')
.addFields(
{ name: 'Server Name', value: `${guild.name}` },
{ name: '\u200B', value: '\u200B' },
{ name: 'Inline field titlve', alue: 'Some value here', inline: true },
{ name: 'Inline field title', value: 'Some value here', inline: true },
)
.setTimestamp()
await interaction.reply({embeds: [exampleEmbed]}) ;
},
};
the above is an example of a slash command with an embed. In my embed, I am trying to print the guild name. Using guild.name. I don't get any error in the terminal but when I run the code in my discord server my bot shows undefined.
What am I doing wrong here and how do I fix it?
Edit: My Config.json:-
{
"token": "Test Test",
"clientId": "Client Id",
"guildId": "Guild Id"
}
P.S. I am kinda new to discord.js and javascript
The problem is that the variable guild is the content of the config.json file. If this file contains an object with the keys guildID and clientID only, guild.name will be undefined.
I think you want to use the guild where the interaction is coming from, in this case, it's interaction.guild:
async execute(interaction) {
const exampleEmbed = new MessageEmbed()
.setColor('#0099ff')
.setTitle(`Server infomation on ${interaction.guild.name}`)
.setDescription('Tells Server Info')
.addFields(
{ name: 'Server Name', value: `${interaction.guild.name}` },
{ name: '\u200B', value: '\u200B' },
{ name: 'Inline field title', value: 'Some value here', inline: true },
{ name: 'Inline field title', value: 'Some value here', inline: true },
)
.setTimestamp();
await interaction.reply({ embeds: [exampleEmbed] });
}