Hi I want to delete a message in Discord.js v12. How do I do that?
I have tried this
message.content.delete()
try this: message.delete()
Ex:
module.exports = {
name: 'sb',
aliases: [],
run: async (client, message, args) => {
message.delete()
message.channel.send(`teest`)
.then(msg => {
setInterval(function() {
msg.edit(`test!`)
}, 3000);
})
}
}
Related
DiscordJS context menu problem, like it says the cmd is running fine but when it does it shows the error of Cannot read properties of undefined (reading 'get') don't know why
Im getting this error on my events folder in discordjs v14 my content.js event
the error kept showing up though the context is still executed/working
I know i should be ignoring this error as long as the command is running good but it just annoying to my console and it doesn't look clean haha...
my context events:
module.exports = {
name: 'interactionCreate',
execute: async (interaction, client) => {
if (interaction.isContextMenuCommand()) {
const { command } = client;
const { commandName } = interaction;
const contextCommand = command.get(commandName);
if (!contextCommand) return;
try {
await contextCommand.execute(client, interaction)
} catch (e) {
console.log(e)
}
}
}
}
simple wave context
const { ApplicationCommandType, EmbedBuilder } = require("discord.js"); // packages
const superagent = require('superagent');
const ee = require('../../Config/embed.json');
module.exports = {
name: 'wave', // name of the command
// description: '', description of the command
developer: false, // false if the command is for public
type: ApplicationCommandType.User, // chatinput
cooldown: 3000, // cooldown of the commands
default_member_permissions: 'SendMessages', // discord perms
// options: [], options string
execute: async (client, interaction) => {
try {
let { body } = await superagent.get(`https://api.waifu.pics/sfw/wave`);
const embed = new EmbedBuilder()
.setColor(ee.color)
.setDescription(`Hey <#${interaction.targetUser.id}>!, <#${interaction.user.id}> just wave at you!`)
.setImage(body.url)
.setTimestamp()
.setFooter({ text: `${client.user.username} | waifumusic.ml` })
interaction.reply({ embeds: [embed] })
} catch (e) {
console.log(e)
}
}
}
For some reason, when using/checking the available slash commands of my bot. I have an echo and hello command, that I have not coded in AT ALL, that just appears. I was wondering if there is anything I can do to remove these?
Here are my packages I am using for this project
"#discordjs/builders": "^0.9.0",
"#discordjs/rest": "^0.1.0-canary.0",
"discord-api-types": "^0.25.2",
"discord.js": "^13.3.1",
"dotenv": "^10.0.0",
"fs": "^0.0.1-security",
"yarn": "^1.22.17"
Here is the interaction Creator
module.exports = {
name: 'interactionCreate',
async execute(interaction, client) {
if (!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({
content: 'There was an error while executing this command!',
ephemeral: true
});
}
},
};
Here is the command handler
const {
REST
} = require('#discordjs/rest');
const {
Routes
} = require('discord-api-types/v9');
const fs = require('fs');
// Place your client and guild ids here
const clientId = '904224432338399243';
const guildId = '922603289898528768';
module.exports = (client) => {
client.handleCommands = async(commandFolders, path) => {
client.commandArray = [];
for (folder of commandFolders) {
const commandFiles = fs.readdirSync(`${path}/${folder}`).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`../commands/${folder}/${file}`);
// Set a new item in the Collection
// With the key as the command name and the value as the exported module
client.commands.set(command.data.name, command);
client.commandArray.push(command.data.toJSON());
}
}
const rest = new REST({
version: '9'
}).setToken(process.env.token);
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: client.commandArray },
);
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
};
};
Mintels!
Try those solutions:
Registering your bot in a single guild (not globally)
Kicking the bot out of the guild and re-inviting it
Leave your code running for some time
Hope this helped and have a great day!
I'm trying to make a ticket system with discord.js v13, but the ephemeral method doesn't work and, when my bot turn on, i need to click one time in the button to activate the system.
print
My code:
const { MessageActionRow, MessageButton, MessageEmbed, Permissions } = require('discord.js');
const db = require("quick.db");
exports.run = async (client, interaction) => {
if (!interaction.isButton()) return;
interaction.deferUpdate();
let getContador = await db.get('counter')
if(getContador === null) {
let contador = await db.set("counter", 1)
}
await db.add("counter", 1)
let tcID = "895323735702253569"
let tmID = "895358127950659604"
const filter = i => i.customId === 'OPENTICKET'
const collector = interaction.channel.createMessageComponentCollector({ filter, max: 1 });
collector.on("collect", async i => {
let cTicket = await i.guild.channels.create(`🎫┆Ticket ${getContador}`, {
type: 'GUILD_TEXT',
permissionOverwrites: [
{
id: i.guild.id,
deny: [Permissions.FLAGS.VIEW_CHANNEL],
},
{
id: i.user.id,
allow: [Permissions.FLAGS.VIEW_CHANNEL, Permissions.FLAGS.SEND_MESSAGES],
},
]
})
await interaction.channel.messages.cache.get(tmID).reply({ content: `... ${cTicket.toString()}...`, ephemeral: true })
})
}
You are replying to a normal message. If you would like an ephemeral message, you have to directly reply to the interaction.
interaction.reply({
content: `... ${cTicket.toString()}...`,
ephemeral: true
})
I am trying this JavaScript ticket code in my discord bot, but the error TypeError: Cannot read property 'guild' of undefined keeps showing up. I don't understand why. Could someone guide me in the correct direction?
module.exports = {
name: "ticket",
aliases: [],
permissions: [],
description: "Open a ticket!",
async execute(message, args, cmd, client, discord) {
const channel = await message.guild.channels.create(`ticket: ${message.author.tag}`);
channel.setParent("820276801652916270");
channel.updateOverwrite(message.guild.id, {
SEND_MESSAGE: false,
VIEW_CHANNEL: false,
});
channel.updateOverwrite(message.author, {
SEND_MESSAGE: true,
VIEW_CHANNEL: true,
});
const reactionMessage = await channel.send("Thank you for contacting support!");
try {
await reactionMessage.react("🔒");
await reactionMessage.react("⛔");
} catch (err) {
channel.send("Error sending emojis!");
throw err;
}
const collector = reactionMessage.createReactionCollector(
(reaction, user) => message.guild.members.cache.find((member) => member.id === user.id).hasPermission("ADMINISTRATOR"),
{ dispose: true }
);
collector.on("collect", (reaction, user) => {
switch (reaction.emoji.name) {
case "🔒":
channel.updateOverwrite(message.author, { SEND_MESSAGES: false });
break;
case "⛔":
channel.send("Deleting this channel in 5 seconds!");
setTimeout(() => channel.delete(), 5000);
break;
}
});
message.channel
.send(`We will be right with you! ${channel}`)
.then((msg) => {
setTimeout(() => msg.delete(), 7000);
setTimeout(() => message.delete(), 3000);
})
.catch((err) => {
throw err;
});
},
}
Using the info in your comment, your command handler was set up incorrectly. When you put execute(message.args), the code tried to pass the args property of your message argument which returns undefined.
Instead, you should use execute(message, args) to properly pass in each argument for your command.
I made in my discord.js bot, command "nuke", which makes channel with same: name, permissions, topic etc, and delete "original" channel. But there is one problem, how to make channel in same position as "original"?
Here's my code:
const Discord = require('discord.js')
module.exports = {
name: 'nuke',
execute(message) {
if (!message.member.hasPermission('ADMINISTRATOR')) {
message.channel.send('missing permissions')
}
message.channel.clone().then(msg => msg.send('nuked'))
message.channel.delete()
},
};
In the docs its stated that you can use setPosition to set the position
const Discord = require('discord.js')
module.exports = {
name: 'nuke',
execute(message) {
if (!message.member.hasPermission('ADMINISTRATOR')) {
message.channel.send('missing permissions')
}
message.channel.clone().then(channel => {
channel.setPosition(message.channel.position)
channel.send('nuked')
})
message.channel.delete()
},
};
Here is a simple piece of code that is not much. Its the nuke command crammed into a tiny piece of coding!
const { MessageEmbed } = require('discord.js')
module.exports = {
name: "nuke",
category: "",
run: async (client, message, args) => {
const link = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT9bZSle1XmET-H9Raq7HZA-7L5JH-zQnEeJKsCam2rcsZmjrLcs2nyTDds1hVNMqS11ck&usqp=CAU"
message.channel.clone().then(channel => channel.send(link + ' ☢️ Channel nuked ☢️'));
message.channel.delete();
}
}
You can also do
const Discord = require('discord.js')
module.exports.run = async (client, message, args) => {
if (!message.member.hasPermission('MANAGE_CHANNELS')) {
message.channel.send('You do not have the required Permissons to do that!')
}
message.channel.clone().then(channel => {
channel.setPosition(message.channel.position)
channel.send('https://i.gifer.com/6Ip.gif')
})
message.channel.delete()
},
module.exports.help = {
name: "nuke"
}