Discord API Error on Deleting a Text Channel - javascript

I have been getting an error as mentioned in the title. Whenever I use that command, the bot creates a channel that brings up a select menu, through which the user can "teleport" to another channel while deleting the newly created channel in the process. This code successfully works twice, after which it gives the error. What should be done to fix the error so that the user can use the command as many times as they'd like? I'll work on this code further once the solution is found, but until then, I'm really stumped here. (Questions shall be answered upon questioning; apologies for the messy coding)
module.exports.run = async (client, msg, args) => {
const guild = client.guilds.cache.get('855845132879921214')
const channel = guild.channels.cache.get('959851265456734319')
const newChannel = await msg.guild.channels.create(`teleporter`)
await newChannel.permissionOverwrites.edit(msg.author.id, {
SEND_MESSAGES: false,
VIEW_CHANNEL: true,
})
const {MessageActionRow, MessageSelectMenu, MessageEmbed} = require('discord.js')
const embed = new MessageEmbed()
.setTitle(`Teleporter!`)
.setDescription("Through this interaction, you can now teleport to the main channel of the desired category!")
const row = new MessageActionRow()
.addComponents(
new MessageSelectMenu()
.setCustomId('teleport')
.setPlaceholder('Choose a channel')
.addOptions([
{
label: 'Rules',
description: "Click to check the rules",
value: 'rules',
},
{
label: 'General',
description: "Click to go to the main chat",
value: 'general',
},
{
label: 'Media',
description: "Click to go to media channel",
value: 'media',
},
{
label: 'Bots',
description: "Click to go to the bots channel",
value: 'bots',
}
]),
)
await newChannel.send({content: `<#${msg.author.id}>`,embeds: [embed], components: [row]})
const wait = require('util').promisify
client.on('interactionCreate', async interaction => {
const member = await interaction.guild.members.fetch({
user: interaction.user.id,
force: true
})
if(!interaction.isSelectMenu()) {
interaction.deferUpdate()}
else if (interaction.values == 'general'){
msg.member.roles.add('958421069650337822')
msg.member.roles.remove('943159431800172584')
let tele = msg.guild.channels.cache.find(channel => channel.name == 'teleporter')
tele.delete()
msg.member.roles.add('943159431800172584')
msg.member.roles.remove('958421069650337822')
}
}
)
}

Don't cache.find and delete, do it like;
const newChannel = await client.channels.fetch("id")
newChannel.delete()

This code should be separated with the first section as your command and the second part as a separate listener, so I have coded as such.
const {
MessageActionRow,
MessageSelectMenu,
MessageEmbed,
} = require('discord.js');
module.exports.run = async (client, msg, args) => {
const guild = client.guilds.cache.get('855845132879921214');
const channel = guild.channels.cache.get('959851265456734319');
const newChannel = await msg.guild.channels.create(`teleporter-${msg.author.username}`, {
permissionOverwrites: [{
id: guild.id,
deny: ["VIEW_CHANNEL"],
}, {
id: msg.author,
deny: ["SEND_MESSAGES"],
allow: ["VIEW_CHANNEL"],
}],
});
// In the event that more than one person uses this command at once, you will need to be able to tell the diffrence when you look up the channel later. So I added the username to the channel name.
const embed = new MessageEmbed()
.setTitle(`Teleporter!`)
.setDescription("Through this interaction, you can now teleport to the main channel of the desired category!");
const row = new MessageActionRow()
.addComponents(
new MessageSelectMenu()
.setCustomId('teleport')
.setPlaceholder('Choose a channel')
.addOptions([{
label: 'Rules',
description: "Click to check the rules",
value: 'rules',
}, {
label: 'General',
description: "Click to go to the main chat",
value: 'general',
}, {
label: 'Media',
description: "Click to go to media channel",
value: 'media',
}, {
label: 'Bots',
description: "Click to go to the bots channel",
value: 'bots',
}]),
);
await newChannel.send({
content: `${msg.author}`,
embeds: [embed],
components: [row],
});
};
This section would go either in the main bot.js file, or if you have your events in seperate files, it would go in the interactionCreate file (may need to be changed a bit if you don't have one, let me know)
const wait = require('util').promisify;
client.on('interactionCreate', async interaction => {
const member = interaction.member;
const guild = interaction.guild;
if (interaction.isSelectMenu()) {
const menuName = interaction.customId;
interaction.deferUpdate();
if (menuName === 'teleport') {
const tele = guild.channels.cache.find(channel => channel.name == `teleporter-${member.user.username}`);
// lookup the channel using the previously mentioned channel name setup
const choice = interaction.value;
if (choice === 'general') {
member.roles.add('958421069650337822');
member.roles.remove('943159431800172584');
} else if (choice === 'rules') {
member.roles.add('roleID');
member.roles.remove('roleID');
} else if (choice === 'media') {
member.roles.add('roleID');
member.roles.remove('roleID');
} else if (choice === 'bots') {
member.roles.add('roleID');
member.roles.remove('roleID');
}
tele.delete();
}
}
});

Related

Discord Bot replies undefined in Embed

My bot only replies undefined with two variables, although I actually defined them.
I dont know why it not works pls help
The command is: you press the button enter a reason and a game in the text input field and then you select a platform from the drop down menu. But instead of sending the embed it says undefined.
My Code:
const Discord = require('discord.js')
const Command = require('../../structures/CommandClass');
const { stripIndents } = require('common-tags');
const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, TextInputStyle, StringSelectMenuBuilder, Events, ModalBuilder, TextInputBuilder } = require('discord.js');
module.exports = class spielersuche extends Command {
constructor(client) {
super(client, {
data: new SlashCommandBuilder()
.setName('sendspielersuche')
.setDescription('Sende das Spielersuche Embed')
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
.setDMPermission(false),
});
}
async run(client, interaction) {
let member = await interaction.member.fetch();
const anfragechannelID = '889302458906591344';
const anfragechannel = member.guild.channels.cache.get(anfragechannelID);
const createanfragechannelID = '1061113274130772058';
const createanfragechannel = member.guild.channels.cache.get(createanfragechannelID);
const pfmenü = new ActionRowBuilder()
.addComponents(
new StringSelectMenuBuilder()
.setCustomId('pfmenü')
.setPlaceholder('Plattform auswählen')
.addOptions(
{
label: 'PS4',
value: 'ps4',
},
{
label: 'PS5',
value: 'ps5',
},
{
label: 'PS4/PS5',
value: 'ps4ps5',
},
{
label: 'PC',
value: 'pc',
},
{
label: 'Switch',
value: 'switch',
},
{
label: 'Alle',
value: 'alle',
},
),
);
const modals = new ModalBuilder()
.setCustomId('minput')
.setTitle('Spielersuche 🔎');
const spielinput = new TextInputBuilder()
.setCustomId('spielinput')
.setLabel("Für welches Spiel?")
.setPlaceholder('GTA5, Fortnite, Call of Duty, Minecraft ...')
.setStyle(TextInputStyle.Short)
.setMinLength(2)
.setMaxLength(20)
.setRequired(true);
const grundinput = new TextInputBuilder()
.setCustomId('grundinput')
.setLabel("Der Grund der Anfrage?")
.setPlaceholder('Beispiel: Suche Spieler für Cayo Perico Heist.')
.setStyle(TextInputStyle.Short)
.setMinLength(10)
.setMaxLength(60)
.setRequired(true);
const firstActionRow = new ActionRowBuilder().addComponents(spielinput);
const secondActionRow = new ActionRowBuilder().addComponents(grundinput);
modals.addComponents(firstActionRow, secondActionRow);
const spielersucheerweitertEmbed = new EmbedBuilder()
.setTitle(`Spieler suchen Spieler 🔎`)
.setColor('#00ff0c')
.setDescription(stripIndents`Drücke auf denn Button um eine Spielersuche Anzufragen!`)
.setFooter({ text: 'YANKEEUNIT91 COMMUNITY'})
.setTimestamp();
const buttonsa = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('buttonanfrage')
.setEmoji('🔎')
.setLabel('Spielersuche Anfragen')
.setStyle(ButtonStyle.Success),
);
client.on('interactionCreate', async interaction => {
if (interaction.isButton()) {
const buttonID = interaction.customId
if (buttonID === 'buttonanfrage') {
await interaction.showModal(modals);
}
}
});
createanfragechannel.send({ embeds: [spielersucheerweitertEmbed], components: [buttonsa] });
await interaction.reply({ content: 'Spielersuche Embed wurde versendet!', ephemeral: true });
client.on(Events.InteractionCreate, async (interaction) => {
if (interaction.isModalSubmit()) {
if (interaction.customId === "minput") {
await interaction.reply({ content:'**Wähle deine Plattform!**', components: [pfmenü], ephemeral: true });
var ginputdata = interaction.fields.getTextInputValue('grundinput');
var sinputdata = interaction.fields.getTextInputValue('spielinput');
}
} else if (interaction.isStringSelectMenu()) {
const selected = await interaction.values.join(', ');
const spielersucheerweitertEmbedfertig = new EmbedBuilder()
.setTitle(`${ginputdata}`)
.setColor('#00ff0c')
.setFooter({ text: 'YANKEEUNIT91 COMMUNITY'})
.setTimestamp()
.addFields(
{
name: '**Spiel:**',
value: `${sinputdata}`,
inline: true,
},
{
name: `**Plattform:**:`,
value: `${selected}`,
inline: false,
},
);
if (interaction.customId === "pfmenü") {
const member = await interaction.member.fetch();
await interaction.update({ content:'**Spielersuche erfolgreich Angefragt!**', components: [], ephemeral: true });
return await anfragechannel.send({ content: `**Anfrage von:** <#${member.id}>`, embeds: [spielersucheerweitertEmbedfertig] });
}
};
});
}
};
tried to define something else but it didn't work
You should focus on where your variables is saved. The variable sinputdata is saved inside the function. The function is like a piece of code that is extracted from the file and ran without really saving variables inside of the function. So every time the function is ran, all your variables are reset.
In other words, you need to save the data you want to keep outside of the function. Therefore, you should make a table at the beginning of your module. Every functions inside the module will be able to edit the table and read the values of it. In addition, everything will be saved (I mean, if you reload the bot, every data will be lost so you need to save everything in a database). Back to the table, the table will include the discordid and the sinputdata value. First, you will set the sinputdata value in the table when you receive it. Then, you will be able to use the sinputdata value when the function is ran a new time.
At the top (under const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, TextInputStyle, StringSelectMenuBuilder, Events, ModalBuilder, TextInputBuilder } = require('discord.js');), write let sinputvalues = {};
Then, instead of var sinputdata = interaction.fields.getTextInputValue('spielinput');, write sinputvalues[interaction.user.id] = interaction.fields.getTextInputValue('spielinput');.
Finally, replace
{
name: '**Spiel:**',
value: `${sinputdata}`,
inline: true,
},
to
{
name: '**Spiel:**',
value: `${sinputvalues[interaction.user.id]}`,
inline: true,
},

Ticket bot only saying the id's

I am back again with a question :). I am building my own ticket function, and I just started but if I create a channel for a ticket, its only saying ticket-(Discord account ID) And thats also the case by the embed. Anyone who can look at it?
const discord = require("discord.js");
const { MessageEmbed, Collection, Permissions} = require('discord.js');
const { execute } = require("./ticket");
module.exports = {
name: 'create',
description: 'create your own ticket.',
execute(message, client, args){
if(message.guild.channels.cache.find(channel => channel.name === "Ticket from <#" + message.author + ">")) {
message.reply(`${message.member.user.toString()} **You have successfully created a ticket, Please click on ${channel} to view your ticket**`).then(m => m.delete({ timeout: 14000 }).catch(e => {}));
if(message.guild.channels.cache.find(channel => channel.name === `ticket-${message.author.id}`)) {
return message.reply('<a:no:784463793366761532> **You already have a ticket, please close your exsisting ticket first before opening a new one**');
}
message.delete();
message.guild.channels.create(`Ticket ${message.author}`, {
permissionOverwrites: [
{
id: message.author.id,
allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
},
{
id: message.guild.roles.everyone,
deny: ['VIEW_CHANNEL'],
},
],
type: 'text',
}).then(async channel => {
const embed = new MessageEmbed()
.setTitle("<#" + message.author + "> Ticket")
.setDescription(`**${message.author}, Welcome to your channel! Support will be arriving soon**\n**While you wait please tell us what your problem is**\n**If you want to close the ticket please type .close\`**`)
.setColor("BLUE")
channel.send({ embeds: [embed] })
});
}
}
}
I cleaned up the code a fair bit, less is more. Text channels do not have spaces in them so I replaced them with what Discord uses, hypens. The below code will check if a channel already exists and create one if it doesn't.
const {
MessageEmbed,
} = require('discord.js');
module.exports = {
name: 'create',
description: 'create your own ticket.',
async execute(message, client, args) {
const channelName = `ticket-${message.author.username}`
const existing = message.guild.channels.cache.find(channel => channel.name === channelName.toLowerCase());
if (existing) {
return message.reply({
content: `<a:no:784463793366761532> **You already have a ticket, please close your exsisting ticket first before opening a new one**\n${existing}.`,
}).then((m) => {
setTimeout(() => {
m.delete();
}, 14000);
})
}
message.delete();
message.guild.channels.create(channelName, {
type: 'GUILD_TEXT',
permissionOverwrites: [{
id: message.guild.id,
deny: ['VIEW_CHANNEL'],
}, {
id: message.author.id,
allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
}],
}).then(async channel => {
const embed = new MessageEmbed()
.setColor("BLUE")
.setTitle(`${message.author.username} Ticket`)
.setDescription(`**${message.author}, Welcome to your channel! Support will be arriving soon**\n**While you wait please tell us what your problem is**\n**If you want to close the ticket please type .close\`**`)
channel.send({
embeds: [embed]
})
});
}
}

I get this error DiscordAPIError: Invalid Form Body

I'm making a ban command for my discord bot and everything's working except for one thing, the embed that the bot is supposed to send to the banned user is not being sent I'm getting a Discord API problem, this problem:
DiscordAPIError: Invalid Form Body
Here is my ban.js file:
module.exports = {
name: 'ban',
description: "This command bans a member!",
async execute(message, args) {
const member = message.mentions.users.first();
if(message.member.roles.cache.has("858091311126806538")) {
if(!message.guild.me.hasPermission("BAN_MEMBERS")) {
return message.channel.send(`**${message.author.username}**, I do not have perms to ban someone`)
}
let banReason = args.join(" ").slice(22);
if (!banReason) {
banReason = "None"
}
if (member) {
const memberTarget = message.guild.members.cache.get(member.id);
const Discord = require('discord.js');
const delay = (msec) => new Promise((resolve) => setTimeout(resolve, msec));
const authoRR = message.author.tag;
const banEmbed = new Discord.MessageEmbed()
.setColor('#ff0000')
.setTitle(`You are banned from Anime Club!`)
.setAuthor(`${authoRR}`, `${message.author.displayAvatarURL()}`)
.setThumbnail(member.displayAvatarURL())
.addFields(
{ name: 'Banned User:', value: `${memberTarget}` },
{ name: 'Ban Reason:', value: `${banReason}` },
{ name: ' ', value: `You were **banned** from Anime Club,
please do not try to rejoin the server or beg the owner to unban you`}
)
.setTimestamp()
message.mentions.users.first().send(banEmbed);
await delay(100);
memberTarget.ban({
reason: banReason
})
const Author = message.author;
const BanEmbed = new Discord.MessageEmbed()
.setColor('#ff0000')
.setTitle(`User has been banned!`)
.setThumbnail(member.displayAvatarURL())
.addFields(
{ name: 'Banned User:', value: `${memberTarget}` },
{ name: 'Ban Reason:', value: `${banReason}` },
{ name: 'Banned by:', value: `${Author}` },
)
message.channel.send(BanEmbed);
} else {
return message.reply(`Please mention a member!`);
}
} else return message.reply(`You must be an administrator to unban a member`)
}
}
Can anyone help? I really don't understand this problem.
The name property of EmbedFieldData cannot be empty. Discord considers a field name empty if it consists only of whitespace characters. If you want to leave the content visibly empty, you could try something like this.
{
name: '** **',
value: `You were **banned** from Anime Club,
please do not try to rejoin the server or beg the owner to unban you`
}

Discord.js Discord bot event listeners stopped working

Some of my discord bot's event listeners stopped working for some reason. Basically i have only two of them: 'guildMemberAdd' event works as intended but 'message' doesn't. Bot simply doesn't recognise !commands sent to it.
My closest assumption is that i messed up sync / async functions.
My main bot.js file:
console.log('Beep Boop Beep'); //prints 'Beep Boop Beep'
require('dotenv').config(); //load the dotenv node pachage and call a config() func to load thea values from .env
const Discord = require('discord.js');
const client = new Discord.Client({ ws: { intents: [
'GUILDS',
'GUILD_MESSAGES',
'GUILD_PRESENCES',
'GUILD_MEMBERS'
] } });
//this line authenticates the bot with the discord API
client.login(process.env.BOTTOKEN);
const embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Some title')
.setURL('https://discord.js.org/')
.setAuthor('Some name', 'https://i.imgur.com/wSTFkRM.png', 'https://discord.js.org')
.setDescription('Some description here')
.setThumbnail('https://i.imgur.com/wSTFkRM.png')
.addFields(
{ name: 'Regular field title', value: 'Some value here' },
{ name: '\u200B', value: '\u200B' },
{ name: 'Inline field title', value: 'Some value here', inline: true },
{ name: 'Inline field title', value: 'Some value here', inline: true },
)
.addField('Inline field title', 'Some value here', true)
.setImage('https://i.imgur.com/wSTFkRM.png')
.setTimestamp()
.setFooter('Some footer text here', 'https://i.imgur.com/wSTFkRM.png');
//exporting those so that they are available in other .js files
module.exports = {client, embed};
function readyDiscord() {
console.log('readyDiscord func executed. Discord is ready.');
}
client.on('ready', readyDiscord);
const commandHandler = require('./commands');
client.on('message', commandHandler);
client.on('guildMemberAdd', async member => {
console.log(member)
const message = `Hey, <#${member.id}>! Welcome. DM me if anytime you want.`
//const channel = member.guild.channels.cache.get(process.env.WELCOME_CHANNEL_ID)
const channel = await member.guild.channels.resolve(process.env.WELCOME_CHANNEL_ID);
channel.send(message)
})
commands.js file:
const hey = require('./commands/hey.js');
const bind = require("./commands/bind.js");
const help = require("./commands/help.js");
const commands = { bind, hey, help };
module.exports = function (msg) {
if (msg.channel.type === 'dm') {
let tokens = msg.content.split(" ");
let command = tokens.shift();
//bot command is only valid when it starts with a !
if (command.charAt(0) === '!') {
//this one removes the !
command = command.substring(1);
commands[command](msg, tokens);
}
}
};
The solution I found was the change up the way you initialize your bot.
Replace this:
const client = new Discord.Client({ ws: { intents: [
'GUILDS',
'GUILD_MESSAGES',
'GUILD_PRESENCES',
'GUILD_MEMBERS'
] } });
With this:
const client = new Discord.Client();
This fixes the code up.

UnhandledPromiseRejectionWarning: ReferenceError: client is not defined

I'm encountering an error while making a command for my discord.js bot which says UnhandledPromiseRejectionWarning: ReferenceError: client is not defined even tho i defined client in the main bot file so i'm pretty confused the code for the command i'm making:
let ticketGen = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split("");
let ticketStr = "";
for(let i = 0; i < 3; i++) {
ticketStr += ticketGen[Math.floor(Math.random() * ticketGen.length)];
}
return ticketStr;
}
const fsn = require("fs-nextra");
const colors = require("colors");
module.exports = {
name: 'order',
description: 'Ordering something',
aliases: ['o'],
execute(message) {
let order = message.content.substring(8);
let customer = message.author.id
fsn.readJSON("./blacklist.json").then((blacklistDB) => {
let entry = blacklistDB[message.guild.id];
// Checks is server is blacklisted or not.
if(entry === undefined) {
// Gets ticket ID.
const ticketID = generateID();
// Sends ticket information to tickets channel.
client.guilds.cache.get("745409671430668389").channels.get("746423099871985755").send({embed: {
color: 0xFFFFFF,
title: message.author.username,
fields: [{
name: "New Order",
value: `${message.author.username} would like to order something.`,
}, {
name: "Order Description",
value: order,
}, {
name: "Order ID",
value: ticketID,
}, {
name: "Guild Infomation",
value: `This order came from ${message.guild} (${message.guild.id}) in ${message.channel} (${message.channel.id}).`,
}, {
name: "Order Status",
value: "Unclaimed",
}],
timestamp: new Date(),
footer: {
text: "Taco Bot"
}
}}).then((m) => {
m = m.id;
//rest of the code
forgive me if it was an stupid error i'm completely new to coding and was watching youtube videos to learn the code for the main bot file:
const fs = require("fs");
const { prefix, token, ownerID } = require('./config.json');
const Discord = require('discord.js');
const client = new Discord.Client();
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.on("ready", () => {
console.log(`ready!.`);
console.log(token);
// Activities
const activities_list = [
`Serving Tacos | .help`,
`Preparing Orders | .help`
];
setInterval(() => {
const index = Math.floor(Math.random() * (activities_list.length - 1) + 1);
client.user.setActivity(activities_list[index]);
}, 10000);
});
//Joined Guild
client.on("guildCreate", (guild) => {
console.log(colors.green(`Joined New Guild, ${guild.name}`));
});
//Left Guild
client.on("guildDelete", (guild) => {
console.log(colors.green(`Left Guild, ${guild.name}`));
});
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
const command = client.commands.get(commandName)
|| client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if (!command) return;
if (command.guildOnly && message.channel.type === 'dm') {
return message.reply('I can\'t execute that command inside DMs!');
}
if (command.args && !args.length) {
let reply = `You didn't provide any arguments, ${message.author}!`;
if (command.usage) {
reply += `\nThe proper usage would be: \`${prefix}${command.name} ${command.usage}\``;
}
return message.channel.send(reply);
}
try {
command.execute(message, args);
} catch (error) {
console.error(error);
message.reply('there was an error trying to execute that command!');
}
});
process.on("error", () => {
console.log("Oops something happened!");
});
client.login(token);
There is no need to create a new client, and absolutely no need to pass it in as an additional argument in your execute method. As you have seen in the comments, the issue is that while client is defined in your main bot file, it is not defined in your command's file. Variables defined in one file aren't accessible in all other files, unless you specifically export that variable using module.exports.
But luckily, you don't need to export your client or pass it as a parameter; discord.js conveniently has a message.client property on the message object which allows you to access your client easily. All you need to do to fix your code is add a single line to the top of your execute() method in your command file:
module.exports = {
name: 'order',
description: 'Ordering something',
aliases: ['o'],
execute(message) {
const client = message.client; //<- Line added right here
let order = message.content.substring(8);
let customer = message.author.id
fsn.readJSON("./blacklist.json").then((blacklistDB) => {
let entry = blacklistDB[message.guild.id];
// Checks is server is blacklisted or not.
if(entry === undefined) {
// Gets ticket ID.
const ticketID = generateID();
// Sends ticket information to tickets channel.
client.guilds.cache.get("745409671430668389").channels.get("746423099871985755").send({embed: {
color: 0xFFFFFF,
title: message.author.username,
fields: [{
name: "New Order",
value: `${message.author.username} would like to order something.`,
}, {
name: "Order Description",
value: order,
}, {
name: "Order ID",
value: ticketID,
}, {
name: "Guild Infomation",
value: `This order came from ${message.guild} (${message.guild.id}) in ${message.channel} (${message.channel.id}).`,
}, {
name: "Order Status",
value: "Unclaimed",
}],
timestamp: new Date(),
footer: {
text: "Taco Bot"
}
}}).then((m) => {
m = m.id;
//rest of the code
And that's all! Problem solved. That message.client property is amazingly convenient.
Relevant Resources:
https://discord.js.org/#/docs/main/stable/class/Message?scrollTo=client
I will suggest you to add the client in the command.execute() too, because it is easier to use. So you will have:
try {
command.execute(client, message, args);
} catch (error) {
console.error(error);
message.reply('there was an error trying to execute that command!');
}
And in every command file you just simply do this.
execute(client, message, args) {
//code
}

Categories