Why doesn't my welcome message in discord.js work? - discord.js

i have tried a lot of different ways but this seemed the most used and successful! But it doesn't seem to work for me? I don't need an embed just a simple message. How do i do this correctly?
client.on('guildMemberAdd', async newMember => {
const welcomeChannel = newMember.guild.channels.cache.find(channel => channel.id === 'my channel id is here')
welcomeChannel.send('welcome we hope you have fun')
})

I've tried your code on myself, it is working exactly just as you intended, so I'm assuming that you might not have put the correct intent. Now discord bot need specific intent (depends on what you are trying to do) to work correctly .
And in your case, you are probably missing the "GUILD_MEMBERS" intent. Change it like:
const client = new Client({
intents: 'GUILD_MEMBERS',
})
Also, in case if you are building a local bot and you don't care about intent or you just simply got annoyed by it.
You can also use
const client = new Client({
intents: 32767,
})

Related

In Discord.JS what is the diffrence between GatewayIntentBits and IntentBits.Flag?

Been working on a discord bot for a while now, and I am still unsure about the difference between GatewayIntentBits and IntentBits.Flag for declaring a new Client in discord.js. I have my code working, but I am curious to know the difference between the two. Any help would be excellent :) thank you in advance.
I'm assuming by IntentBits you meant IntentsBitField because of how you mentioned the "Flags" property and I've seen that method used before
GatewayIntentBits provides just the flags you can refer to and nothing else. IntentsBitField is a special structure in discord.js that allows you to modify a bitfield, using functions like add() and remove(). Here's an example from the discord.js guide:
const { Client, IntentsBitField } = require('discord.js');
const myIntents = new IntentsBitField();
myIntents.add(IntentsBitField.Flags.GuildPresences, IntentsBitField.Flags.GuildMembers);
const client = new Client({ intents: myIntents });
If you just need to decide which one to use to set the intents of your bot, I don't believe there's a difference - except GatewayIntentBits is fewer characters to type :)

"message.content" doesn't work in DMs - Discord.js

I tried to make a ping command for a DM channel, so if an author says ping in a DM channel, a bot could reply pong, but it’s not working. The console is not giving any error and the bot is not providing any output.
message.content doesn’t work in DMs.
client.on('messageCreate', (message) => {
if(message.author.bot) return
//command
if (message.content.toLowerCase() === `ping`) {
message.author.send(`pong`);
}
});
While the coco bar's answer is something that needs to be done, it may not be the full answer to the problems you are having. Something else you will want to make sure that you have enabled in the bot code is your intents. Somewhere in your code you have a line that starts off like this (may not be exactly this):
const client = new Client({})
Make sure you have your intents enabled there.
Example 1 enables minimum intents:
const client = new Client({
intents: ['GUILDS', 'GUILD_MEMBERS', 'GUILD_MESSAGES', 'DIRECT_MESSAGES'],
})
Example 2 enables all intents:
const client = new Client({
intents: 131071,
})
Example 3 enables all intents with partials:
const client = new Client({
intents: 131071,
partials: ['CHANNEL', 'GUILD_MEMBER', 'GUILD_SCHEDULED_EVENT', 'MESSAGE', 'REACTION', 'USER']
})
UPDATE intents: 32767 no longer includes all intents; all intents are now 131071
message.author doesn't have any content property. If you want to check the message content, use MessageComponent#content as stated in the documentation.
Also make sure you enabled the correct intents and asked for verification if you bot is over 100 guilds.
You are missing an intents
Intents.FLAGS.DIRECT_MESSAGES,
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS,
Intents.FLAGS.DIRECT_MESSAGE_TYPING,
or
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_MEMBERS","DIRECT_MESSAGES","DIRECT_MESSAGE_REACTIONS","DIRECT_MESSAGE_TYPING"] });
Go to the Discord developers site and make sure that your message content intents are turned on, and everything should work fine now.

Is there an easy way to make my bot mention the person its moving?

so basically I wanted to make my bot move people to afk as soon as they deafen. and I have a command to make it generate messages in chat, but the question is, can I make it # them as well? and if so how?
code:
const Discord = require("discord.js");
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_VOICE_STATES", "GUILD_MEMBERS", "GUILD_PRESENCES"] });
client.on("voiceStateUpdate", (oldState, newState) =>
{
if (newState.selfDeaf)
{
console.log('User has deafened');
newState.member.voice.setChannel("695840093167943751");
client.channels.cache.get("664487959940169738").send('Undeafen Bitch');
}
To tag a user in discord, the format is <#USERID> so if a user's id is 1, you'd have to include <#1> in what you are sending.
So onto your code, you'd have to change the last line to something like the following:
client.channels.cache.get("664487959940169738").send('<#123> Undeafen Bitch');
But we can't hardcode the id since it'll be unique for each user moved. This should automatically tag the user who got moved:
client.channels.cache.get("664487959940169738").send(`<#${newState.member.id}> Undeafen Bitch`);

Discord Missing Intent Error on discord.js

Im having trouble launching my code for the past 6 hours it was working fine yesterday but it doesnt seem to work any more i keep on having an error that says ('CLIENT_MISSING_INTENT')
this is my starting code i dont understand what i am doing wrong
const Discord = require('discord.js'),
welcome = require('./welcome'),
mute = require('./mute'),
unmute = require('./unmute'),
mongoose = require('mongoose'),
Levels = require("discord-xp")
const { Client, Intents } = require("discord.js");
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});
You're quite literally missing an Intent. As you're probably already aware based on your code, v13 of discord.js requires you to add certain Intents to avoid processing power being thrown away to features not used.
You can look at all Intents available here, and try to add a few of them to see which one you need. Based on your code I can't see which one you're missing.

Creating a Discord bot to notify people when to certain text on a website has changed

const Discord = require('discord.js');
const bot = new Discord.Client();
const token = '';
bot.on('ready', () =>{
console.log('This bot is online');
})
bot.on('message', msg=>{
if(msg.content === "?rates"){
msg.reply('.')
}
})
bot.login(token);
This is what I have so far it is very basic, I understand, I'm just trying to get some sort of idea how to process. What I want is as soon as a website gets updated or changed. I would like it to tag everyone and in a certain channel and specifies what has changed. I know this will be a long process but I'm in for the ride :) would appreciate any help.
You need a webhook on the website and listen to it with your bot, if you have control over the site, this may help you, otherwise you could look if the site has one or perhaps ask an owner.
A probably working but not very nice (and not very clean) solution would be to save the text of the website every 5 seconds or so and compare it to the previous save. If it changed, you notify the members through sending a message.

Resources