How can I send a message to 2 server the bot is in with node discord - discord

I would like it so that when I type a command and a message it will forward that message to a channel in 2 server the bot is connected to with node discord.
Thanx :)

You can use
var message = '[Message]';
bot.channels.get('[ChannelIDServer1]').send(message);
bot.channels.get('[ChannelIDServer2]').send(message);
To get the ID of a channel just right click the channel -> copy ID
If you have named your client differently just change bot to the name you use.
const Discord = require('discord.js');
const bot = new Discord.Client();

Related

I need a code that sends a message every time a channel is created

I want my bot to send the message "first" every time a channel is created
the closest I could get was at Discord JS : How can ı send message when create channel by bot but I don't want to that he sends the message only on channels he created himself, but on channels created by anyone
You can use the channelCreate event.
Here's a simple example for you:
client.on("channelCreate", async (channel) => {
const channelName = channel.name;
console.log(`New channel created: ${channelName}`);
});

Discord.js Voice Channel with Slash Commands

I want to create a Music Bot with the new Discord Slash Commands, but I don't know how to get the voice channel which the user is in.
With a normal Message-Command it's message.member.voice.channel.
Because interaction.member doesn't contain any voice information, i defined the voice channel as follows:
const guild = client.guilds.cache.get(interaction.guild_id)
const member = guild.members.cache.get(interaction.member.user.id);
const voiceChannel = member.voice.channel;
const guild = client.guilds.cache.get(interaction.guild_id)
const member = guild.member(interaction.member.user.id)
const vchannel = member.voice.channel
vchannel.join()
This is what worked for me.
You can use Interaction#member which will return the member who sent the interaction if it was sent in a guild, or null if it was not sent in a guild.
const voice_channel_id = interaction.guild.members.cache.get(interaction.member.user.id).voice.channelId

Trying to make a discord bot direct message new members. What am I doing wrong?

Trying to make a discord bot direct message new members. What am I doing wrong?
const Discord = require('discord.js');
const bot = new Discord.Client();
bot.on('guildMemberAdd', member => {
member.send("Welcome to the server!");
});
bot.login('TOKEN_HERE');
Everything is correct. The only thing you have to do is to enable some settings to make it work. First, go to the Developer Portal. Second, go to your application and go to "Bot". Third, click the 2 buttons in the "Privileged Gateway Intents" and you are good to go! Also, if you want to add me on Discord, this is my username: Jellybee#4284.

Discord guildMemberAdd stopped working suddenly

the bot was working good then suddenly the welcome msgs stopped working my discord.js verson is 12.4.1 what i should do
here is my code
const { Client, RichEmbed,Attachment } = require('discord.js');
const bot = new Client();
const client = new Discord.Client()
client.on("guildMemberAdd", member => {
const channel2 = member.guild.channels.get("channelID")
channel2.send(`${member} has join to Our Style server`)
})
There was an update in discord and from now on, you have to enable some options for it to work:
Visit https://discord.com/developers/applications
Click on the bot where you wish to enable privileged intents
Navigate to the "Bot" tab on the left
Scroll to the Privileged Gateway Intents section
Enable your desired intents (in this case SERVER MEMBERS INTENT one)
Then it should work again. If it still won't, then try turning on PRESENCE INTENTS too.

How to create a discord bot that only allows a specific word in a certain text channel

I am trying to create a discord bot that only allows the word "upgrade" in a certain text channel.
As I am very new to this I would like to learn about how this is done.
Its easy. First create a bot. I guess you know about node.js if not, find tutorials for creating a project with discord.js.
First create a client:
const Discord = require("discord.js");
const client = new Discord.Client();
client.login("SuperSecretBotTokenHere");
(make sure you have a bot token) discordapp.com/developers
Then you create a message event:
client.on("message", (message) => {
if(message.content != "upgrade") return message.delete()
});
Put your bot in the server, give it permissions to delete messages in the channel aaand done!
Sorry for my bad English.

Resources