How to send a message to every user that is in same guild as bot? - discord.js

So basically I want to make bot able to send a message to every user that is in the same guild as a bot, I want to make it with a timeout, so I don't abuse Discord API.

Sending DM's using setTimeout would take forever so I filtered guilds with a channel named auto-partnership
setTimeout(() => {
let channel = client.channels.cache.filter(channel => channel.name.toLowerCase() === "auto-partnership")
channel.forEach(channel => {
channel.send( "test")
})
}, 5000);
A bot is sending test message to every guild with a channel named auto-partnership

Related

Im trying to send a dm but doesn't work (DJs)

so im trying to make a selfbot and before receiving 5 hundred message saying it isnt very tos friendly,i take this risk.So im trying to send a message to an user and idk why it sends a dm only to people my bot already has a dm channel opened.
Code :
setInterval(async () => {
const guild = client.guilds.cache.get("758345919350964254");
if(!guild) return; // pour évité toute erreur
guild.members.fetch();
guild.members.cache.random().createDM().then((dm => {
dm.send("Dont forget to verify !").catch(e => console.log('e'))
})).catch(() => {})
console.log("message sent")
}, 3000000);
console.log('ca marche')
I want my bot to sends dm not only to people my bot already has a dm Channel created with.

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

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

How to get the user which added the bot?

i'm currently working on a Discord.js bot and i want that i get the id or name of the user which added the bot to the guild.
I want that the person which added the bot gets a DM.
Thanks for the answers!
client.on("guildCreate", guild => { // This event fires when a guild is created or when the bot is added to a guild.
guild.fetchAuditLogs({type: "BOT_ADD", limit: 1}).then(log => { // Fetching 1 entry from the AuditLogs for BOT_ADD.
log.entries.first().executor.send(`Thank you for adding me to ${guild.name}!`).catch(e => console.error(e)); // Sending the message to the executor.
});
});

How to know the inviter of the bot ? discord.js

I want to know who is the inviter of the bot but I don't find anything on the documentation or on forum.
If someone has an idea :/
EDIT
Recently discord added an entry in guild audit logs that log everytime someone adds a bot into the server, so you can use it to know who added the bot.
Example:
// client needs to be instance of Discord.Client
// Listen to guildCreate event
client.on("guildCreate", async guild => {
// Fetch audit logs
const logs = await guild.fetchAuditLogs()
// Find a BOT_ADD log
const log = logs.entries.find(l => l.action === "BOT_ADD" && l.target.id === client.user.id)
// If the log exits, send message to it's executor
if(log) log.executor.send("Thanks for adding the bot")
})
Old Anwser
The discord API doesn't allow this.
But, you can send a message to the Owner of the guild using the property guild.owner to get it
client.on('guildCreate', guild => {
guild.owner.send('Message here').catch(e => {
// Can't message to this user
})
})

Resources