How to check what servers your Discord Bot is in [discord.js] - 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.

Related

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.

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