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

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

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

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 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