Im trying to send a dm but doesn't work (DJs) - discord.js

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.

Related

Discord JS - If user sends DM to bot with specific string

The code below works and send a DM to the user when he/she reacts to a message.
The goal is then to add a role - or do something - if the user replies with the correct string.
if (reaction.emoji.name === theDoor) {
await reaction.message.guild.members.cache.get(user.id).roles.add(treasure);
const reactUser = await reaction.message.guild.members.cache.get(user.id);
reactUser.send('Enter the code. Hint: *Yumi Zouma*.');
} else {
return;
}
How can I make the bot handle DM from other users? Google seems to only provide how to send a DM to a user.
What you need to use then is a Message Collector.
Docs
For example,
const dm = await reactUser.send("Enter code")
const collector = dm.channel.createMessageCollector({filter, max: 5, time: 30000}); //We're creating the collector, allowing for a max of 5 messages or 30 seconds runtime.
collector.on('collect', m => {
console.log(m.content)
}
collector.on('end', (collected, reason) => {
await dm.channel.send({content: `Collector ended for reason: ${reason} reached! I collected ${collected.size} messages.`})
}

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 send a message to every user that is in same guild as bot?

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

How do you make some bot commands only work in some discord channels

This is my first time using js. I need to ban a certain word in a certain channel. I don't want the message to be deleted if it is not in the specific channel.
For Example:
I want to ban the word "goodbye" in the #greeting channel
BUT
I don't want to ban the word "goodbye" In the #farewell channel
How would I go about this?
Thanks.
By the way I wanted to use example code, but none of it made any sense.
I wrote a simple example for you on how to achieve this:
const Discord = require("discord.js");
const Client = new Discord.Client();
const ForbiddenWords = {
"ChannelID": ["goodbaye", "bye"] // Greeting channel
};
Client.on("ready", () => {
console.log(`${Client.user.tag} is ready!`);
});
Client.on("message", (message) => { // Fired when the bot detects a new message.
if (message.author.bot) {return false}; // Checking if the message author is a bot.
if (ForbiddenWords[message.channel.id]) { // Checking if the current channel has any forbidden words in the ForbiddenWords Object
if (ForbiddenWords[message.channel.id].some(word => message.content.toString().toLowerCase().includes(word))) { // Checking if the message contains any forbidden words
message.delete(); // Deleting the message.
};
};
});
Client.login(process.env.DISCORD_AUTH_TOKEN);

How to list user by discord bot

I want to know how to show all user that join discord channel by discord bot
.
.
.
(I know a little about discord.js & discord API)
bot.on('message', message => {
const listedUsers = [];
message.guild.channels.forEach(user => {
message.channel.send(message.author.username)
}
message.channel.send(listedUsers)
}
I realise this will send every user in a channel in a lot of messages - but I hope this works

Resources