My discord bot is not pinging everyone. It is sending the #everyone message, but its not pinging anybody. (Discord.js V13) - discord.js

My discord bot is not mentioning anybody after sending #everyone. Like, it is sending the #everyone message. But it doesn't ping anybody. I have my bot's permissions with pinging everyone enabled. But it still doesn't work.
Here's the code:
const discord = require('discord.js');
module.exports = {
info: {
name: "announcement",
description: "Announcement!",
},
name: "announcement",
description: "Announcement!",
async execute(Discord, client, interaction){
await interaction.reply(`#everyone`);
}
}
I expect the bot to ping everyone, and it doesn't. That's the issue.

Use allowedMentions:{parse:["everyone"]} as option when sending a reply or message. For example: interaction.reply({content:'#everyone',allowedMentions:{parse:["everyone"]}})

You can change your client constructor to be as follows:
const client = new Discord.Client({
intents: 32767,
allowedMentions: {parse: ["roles", "users"], repliedUser: true}//this enables #everyone mention (parse users)
});

Related

POST Error when using Discord Webhook in Dev Console on discord.com

I am using a piece of JS I saw in an online tutorial to send a webhook to a discord server I own. When I run the code from localhost on my computer it sends the webhook no problem. However, when I paste the same code into the console on a tab with discord open, the code does not run and I receive a POST error 400. It was working a month ago, What am I doing wrong?
Please note the webhook url shown is not real. Below is the JS I am using:
function sendMessage() {
const request = new XMLHttpRequest();
request.open("POST", "https://discordapp.com/api/webhooks/676118118082281513/ZS5YcWhurzokBrKX9NgexqtxrJA5Pu2Bo4i7_JsIxC-JIbPBVhSZkcVVukGOro52rnQA");
request.setRequestHeader('Content-type', 'application/json');
const params = {
username: "My Webhook Name",
avatar_url: "",
content: "The message to send"
}
request.send(JSON.stringify(params));
}
sendMessage()

How can i setup my discord bot automatically?

I have a discord bot but I want when someone add my bot to their server they dont need to write !setup. How I can do it automatically ?
client.on('messageCreate', async message => {
if (message.content === '!setup') {
await message.guild.commands
.set(client.commands)
}
});
Use the Client#guildCreate event
For instance:
client.on("guildCreate", guild => {
// What to do when the bot is invited
}
Under client in the discord.js docs there is an event called guildCreate which is emitted when the client joins a guild. If you listen for this event and run your setup code when it is emitted this might be what your after.
const { Client, Intents} = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.on('guildCreate', guild => {
//Your setup code
});
If it's just one server that you wan to add the bot to, you can do it manually. Just follow these steps:
Go into discord developer portal > click on your bot > Oauth2 > URl Generator > click bot and any other scope you might need > choose your perms > copy and past the link into your browser and you should be done!
To do this however, you must have manage server perms in that server

Discord bot not online

Im doing a course off UDEMY, how to create a discord bot that responds to messages, ive created the bot and all however, i am following all of the instructors instructions yet his bot shows "online" and mine does not.
// token:
// invite link for bot: https://discord.com/api/oauth2/authorize?client_id=984130743578034216&permissions=2048&scope=bot
const Discord = require("discord.js");
const Client = new Discord.Client({ intents : ["GUILDS", "GUILD_MESSAGES", "DIRECT_MESSAGES"]});
Client.login("");

guildMemberAdd event not working even with intents enabled. (discord.js)

I'm trying to set up a welcome message function on my discord bot, but no matter what I do, the bot doesn't seem to be able to use guildMemberAdd. I'm aware of the new update, and as suggested I've turned on both options under Private Giveaway Intents. But it still does not work. Here is my code:
client.on('guildMemberAdd', member => {
const emb = new MessageEmbed()
.setColor('#FFBCC9')
.setTitle("new member")
.setDescription("welcome to the server!")
member.guild.channels.get('780902470657376298').send(emb);
});
I have also found an answer online suggesting to use this:
const { Client, Intents } = require("discord.js");
const client = new Discord.Client({ ws: { intents: new Discord.Intents(Discord.Intents.ALL) }});
But no matter how I write that, my bot just won't even come online unless I use const client = new Discord.Client(); with nothing in the parentheses.
With v12 coming along, in order to get your full channels list you're only able to get the cached ones in your server. Hence why you should change this line:
member.guild.channels.get('780902470657376298').send(emb);
to:
member.guild.channels.cache.get('780902470657376298').send(emb);
You passed in the intents params wrong. Here is the correct way to do it.
const { Client, Intents } = require("discord.js");
const client = new Discord.Client({ ws: { intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_MEMBERS', 'GUILD_PRESENCES'] } });
If you use this the guildMemberAdd event will emit.
Make sure you have intents turned on in the developer portal. As Shown in this image https://i.imgur.com/WfBLtXY.png.

How i can make a discord bot in specific channel delete and resends msg

How i can make a discord bot in specific channel and who ever write delete that message and resend it ?
Assuming you want the bot to resend any message as the bot in a specific channel here's an example using Discord.js
If I misunderstood and you want the bot to send a message as a specific user, that's not possible.
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('message', msg => {
if (msg.channel.name === 'channel name') {
msg.delete();
msg.channel.send(msg.content);
}
});
client.login('token');

Resources