Discord bot clear command - javascript

I would like my bot to delete only two messages but I don't know what command I have to do for it to do that.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
await lib.discord.channels['#0.1.1'].messages.destroy({
message_id: `${context.params.event.message.id}`,
channel_id: `${context.params.event.message.channel_id}`
});

Related

Bot not responding to message

I'm new to this and have been following a tutorial online but I cannot figure out why the bot will not respond to the message.
Things I have checked:
the tokens match up
bot has proper permissions
not missing any ";" etc etc
Here is the code for reference
const Discord = require('discord.js');
const bot = new Discord.Client({ intents: [Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMessages, Discord.GatewayIntentBits.DirectMessages] });
const token = <token>;
bot.on('ready' , () =>{
console.log('ts ready gangy :3');
})
bot.on('message', msg=>{
if(msg.content === "hi"){
msg.reply('hi');
}
})
bot.login(token);
The code runs and the bot will appear online as normal but when inputting "hi" and sending it, the bot gives no response.
Add Discord.GatewayIntentBits.MessageContent to your intents and tick Message Content Intent if you didn't tick

Discord bot not on members list but online

I'm trying to start my first discord bot. Installed NodeJS on my PC, started app in discord dev tools, make it bot, got token, selected priviliges, added bot to my server. Actually another bot i already have even sent welcome message saying my new bot joined the server. When i start it using command "node main.js" it says it went online, doesn't give any errors, however my bot isn't showing in members list (neither offline nor online) and it doesn't react to messages with its prefix. Here's my main.js code:
const Discord = require('discord.js');
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const prefix = '=';
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'status') {
console.log(command);
message.channel.send('Bot dziala poprawnie.');
}
} );
client.once('ready', () => {
console.log('GuruBot online');
});
client.login('my_token_is_here');```
The bot probably doesn't have access to the text channel. Check the bot's permissions on your server, and check the invite link that you're using to make sure that the bot can view channels and incoming messages.
I'm very late to the question, but hopefully this will help anyone who is searching for this issue.

I need help making my bot dm me not the author of the command

So I have a main.js that already does the see what the command is so it knows im trying to do !report and is able to say text. I've also gotten it to dm the user who sent it - but not to dm me. (this is set up like the rest of my commands however those are just making the bot talk basically) The goal being it will tell me if someone needs help and I can just dm them to ask about what is going on. (I removed my ID and replace it with "My ID")
const Discord = require('discord.js');
const client = new Discord.Client();
const BluntSam = client.users.cache.get('My ID');
module.exports = {
name: 'report',
description: "Report a problem with this bot, channel, or people.",
execute(message, args){
if (message.toString().toLowerCase().includes('report')) {
message.author.send('Your report request has been sent. Please wait for a response from <#My ID>.');
message.author.send(message.author + ' has requested an assistance ticket.')
}
}
}
Get your user. Use an async function or IIFE for this.
Message it.
(async () => {
let me = await client.users.fetch('YOUR-USER-ID');
me.send('some message');
})();

discord bot help command doesn't do anything

I'm making a discord bot but when I do my help command nothing happens.
The code for my help command is:
const Discord = require('discord.js');
module.exports.run = async (client, message, args) => {
const Embed = new Discord.RichEmbed()
.setColor("YELLOW")
.setTitle("HardBot - Help")
.setDescription(":tada: Subscribe to our YouTube channel!")
.addField("meme", "youtube",true)
.addField("servers", "ping",true)
.addField("invite",true)
.addField("our prefix is h!",true);
message.channel.send(Embed)
}
module.exports.help = {
name: "help"
}
Make sure to update discord.js by using npm i discord.js#latest in your terminal. Then replace RichEmbed with MessageEmbed.
For all changes in discord.js v12 click here.
Edit:
Make sure you fill every field from an embed with values otherwise it is an invalid form body.

How to remove a message after a specific period of time in DiscordJS?

I have a question demanding DiscordJS.
It is, how to properly delete a Discord message that the bot sent?
I know it's a newbie question, but I'm new to DiscordJS.
I'm very thankful for all the responses I get, no matter if helpful or not.
You have to use the .delete method for the message object in order to delete the message. Just wait until the message is sent and then delete it after a certain period of time.
For (Rich)embeds, use the following code:
const Discord = require('discord.js');
const RichEmbed = new Discord.RichEmbed()
.setAuthor('test');
const message = await message.channel.send({ embed: RichEmbed }).then(r => r.delete('time in milliseconds'));
For normal messages, use the following code:
const message = await message.channel.send('Hello').then(r => r.delete('time in milliseconds'))

Categories

Resources