Discord bot not online - discord

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("");

Related

How to check what servers your Discord Bot is in [discord.js]

How would I check what servers my discord bot is in, code wise in discordjs.
And able to join those servers.
You can view the guilds (servers) your bot is in with <Client>#guilds. Example:
const { Client, GatewayIntentBits } = require('discord.js');
const bot = new Client({ intents: [GatewayIntentBits.Guilds] });
console.log(bot.guilds.cache.map(guild => guild.id));
bot.login('YOUR_TOKEN');
This will return an array of the ids of the guilds your bot is a member of.

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

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)
});

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.

Bot comes online but the embed won't post on discord

i'm new to programming and started making a discord bot by watching a few tutorials. I want the bot to DM the discord embed to the user who types "-buy" in a text channel. When running the code, the bot comes online and runs the "your bot name is online!" but no DM is sent. I would greatly appreciate any help. Thanks
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = '-';
client.once('ready', () => {
console.log('your bot name is online!');
});
client.on('message', message =>{
if(message.author.client) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLocaleLowerCase();
if(command === 'buy'){
const testEmbed = new Discord.MessageEmbed()
.setColor(0x7f03fc)
.setTitle('test embeddy')
.setDescription('test description woo')
.setFooter('this is the footer')
try {
message.author.send(testEmbed);
} catch {
message.reply('Sorry I cannot message you! Check if your DMs are public!')
}
}
});
client.login('');
the token isn't the problem, i deleted it so i could upload here
The message.author.client returns the bot client, and it doesn't return a boolean. So your bot is blocked from there. Try removing that code and write message.author.bot that returns a boolean if the message author is a bot user. It will work.

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