-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (47 loc) · 1.88 KB
/
index.js
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
44
45
46
47
48
49
50
51
const { Client, Intents, MessageButton, MessageActionRow } = require('discord.js');
const { prefix, token, roleId, emojiId } = require('./config.json');
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_PRESENCES
]
})
client.on('ready', async () => {
console.log('Ready!');
client.user.setActivity(``, { type: "LISTENING" })
client.user.setStatus('online') //online, dnd, idle
})
client.on('messageCreate', async (msg) => {
const args = msg.content.slice(prefix.length).trim().split(/ +/).filter(Boolean);
if (msg.content.startsWith(prefix)) {
if (args[0] === `send`) {
const channel = msg.mentions.channels.first() || msg.guild.channels.cache.get(args[1]);
if (!channel) return msg.reply('Please provide a valid channel mention or ID.');
const button = new MessageButton()
.setCustomId('verify-button')
.setLabel('Verify')
.setStyle('SUCCESS')
.setEmoji(emojiId)
const row = new MessageActionRow()
.setComponents([button])
channel.send({ content: 'Click button below to verify', components: [row] })
msg.reply('Successfully sent message')
}
}
})
client.on('interactionCreate', async (interaction) => {
if (!interaction.isButton()) return
const { customId, guild, member } = interaction
if (customId === 'verify-button') {
try {
await member.roles.add(roleId)
interaction.reply({ content: 'Success', ephemeral: true })
} catch (e) {
console.error(e)
interaction.reply({ content: 'Something went wrong', ephemeral: true })
}
}
})
client.login(token)