he don't view new member and don't write on console "nouveau membre"
Client.on("guildMemberAdd", (member, guild) => {
console.log("nouveau membre");
})
You need to have SERVER_MEMBERS_INTENT in order to receive the guildMemberAdd event.
If you have a verified bot then it needs whitelisting, if not then just go to your application and to the bot tab and toggle the server members intent
Related
When my Discord bot joins a guild, I want to send a private message to the member inviting the bot. I am using Discord.js.
Now, i know there is a guildCreate event i can use on the client, that fires when the bot joins a guild.
This event however, only provides the Guild the bot has been invited in.
I've seen multiple bots sending me private messages this way, so i know there must be a way. One could get the guild owner and send him private message, but there is a chance that the owner is not the one inviting the bot. And unfortunately, since i was always the owner when it happened, i can't say if it was this or not.
Is there a way to retrieve the GuildMember, or the User that invited the bot ?
This requires view audit log permissions for the bot:
let logs = await guild.fetchAuditLogs()
logs = logs.entries.filter(e => e.action === "BOT_ADD")
let user = logs.find(l => l.target?.id === client.user.id)?.executor
//user is the inviter
I've made a code which greets new members in a particular channel but I want to toggle it.
If a staff member uses !greet #channel then greet messages will be enabled in #channel. And if they use !greet, it disables greet message for the server.
GuildMemberAdd Event
client.on('guildMemberAdd', member =>{
const channel = member.guild.channels.cache.find(ch => ch.name == 'welcome');
if(!channel) return;
channel.send(`Welcome to **${member.guild.name}**, ${member}!`)
.then(message =>{
message.delete({ timeout: 5000 })
})
.catch(console.error);
});
More Info
I just want to make it a toggle command and I'm not sure how to. I'd be glad for an early answer.
So to toggle which channel will be send welcome message you need to store the channel ID somewhere like database or attach it with guild through collection .set . After that in your event before send message you get information from guild ID if it already set welcome channel so send message to that channel otherwise don't do anything
What I am trying to do is set up an autoresponse discord bot that adds a reaction to any message that is being sent,in a specific channel. I cannot figure out why it is not showing up in discord.
It's very simple, just add a message event listener, validate if the channel id is the one you want it to be, and then use the .react method. For example:
client.on('message', message => {
if (message.channel.id !== 'channel id here') return;
message.react('emoji here')
// if you want to use a custom emoji put it's id there instead.
})
I'm making a bot to detect when a user joined. The code below does not work when my test account joins. Does it only work when it's the first time a user joins. If so, how can I make it work everytime.
client.on('guildMemberAdd', member => {
// Send the message to a designated channel on a server:
const channel = member.guild.channels.cache.find(ch => ch.name === 'general-chat');
// Do nothing if the channel wasn't found on this server
if (!channel) return;
// Send the message, mentioning the member
channel.send(`Welcome to the server, ${member}`);
});
You might have to enable Presence Intent on your bot settings on the Discord Developer Portal, which makes it able to detect new members.Here's an screenshot.
In my discord server, as a verification method, I want my bot to have all users react to the message and then get given the verified role, and remove the old role. The current code I have doesn't grant or remove roles, but doesn't error.
client.on("messageReactionAdd", function(users) {
users.addRole(users.guild.roles.find("name", setup.verify));
users.removeRole(users.guild.roles.find("name", setup.default));
});
There is a problem in the current code. The messageReactionAdd event returns a User object, which does not contain the property .guilds which you attempt to access: users.guilds.r- .
Instead of this perhaps you should the id of the User object and plug that into message.guild.members.get("id here"). Then use the returned Member object with your current code. That should work!
References:
Guild Member
, Message Reaction Event, User Object
Would something like this work?
I'm not sure it will I haven't tested it. This should add the role if the message they reacted to consists of the word "role1" and if they react to a different message it will remove the role. I don't know if this is what you're going for but in theory this should work.
client.on("MessageReactionAdd", function(users) {
if (message.content === "role1") {
users.addRole(users.guild.roles.find("name", setup.verify))
} else if (!message.content === "role1") {
user.removeRole(users.guild.role.find("name", setup.default))
}
});
Are the names of the roles; setup.verify & setup.default?
If not, that's why it is not working.
Try:
client.on("messageReactionAdd", function(users) {
users.addRole(users.guild.roles.find("id", ROLEIDHERE));
users.removeRole(users.guild.roles.find("id", ROLEIDHERE));
});
where ROLEIDHERE put the role id to find the role id just tag the role and before you hit send put \ before the tag and it will supply the id