-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (28 loc) · 915 Bytes
/
index.js
File metadata and controls
43 lines (28 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers
]
});
const TARGET_SERVER_ID = 'SERVERID';
const MEMBER_ROLE_ID = 'ROLEID';
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('guildMemberAdd', async (member) => {
if (member.guild.id === TARGET_SERVER_ID) {
try {
const role = member.guild.roles.cache.get(MEMBER_ROLE_ID);
if (!role) {
console.error('member role not found');
return;
}
await member.roles.add(role);
console.log(`gave member tole to ${member.user.tag}`);
} catch (error) {
console.error('error giving role:', error);
}
}
});
client.login('token');