-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
50 lines (41 loc) · 1.4 KB
/
main.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
const { Client, ActionRowBuilder, ButtonBuilder } = require('discord.js')
const { hasTwitterLink, getVxTwitterLink } = require('./functions/regex')
const deleteMessage = require('./interactions/buttons/deleteMessage')
require('dotenv').config()
const bot = new Client({ intents: 3276799 })
bot.on('ready', async () => {
console.log(`🚀 ${bot.user.username} is running!`)
})
bot.on('messageCreate', async message => {
if (!hasTwitterLink(message.content) || message.author.bot) return
const resp = await getVxTwitterLink(message.content)
if (resp.video <= 0) return
const deleteButton = new ActionRowBuilder()
.addComponents([
new ButtonBuilder()
.setCustomId(JSON.stringify({
id: 'deleteMessage',
userId: message.author.id
}))
.setLabel('Delete')
.setStyle(4)
.setDisabled(false)
])
message.reply({
content: `> <@!${message.author.id}>\n${resp.message}`,
components: [deleteButton]
})
.then(m => message.delete())
.catch(console.error)
})
bot.on('interactionCreate', async interaction => {
if (interaction.isButton())
interaction
.deferUpdate()
.then(() => {
const json = JSON.parse(interaction.customId)
if (json.id.normalize() === 'deleteMessage'.normalize()) deleteMessage(interaction, json).catch(console.error)
})
.catch(console.error)
})
bot.login(process.env.TOKEN)