-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
112 lines (90 loc) · 2.76 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//yes code is beautified
const {
Client,
Intents,
MessageAttachment,
MessageEmbed,
Constants
} = require('discord.js');
const {
REST
} = require('@discordjs/rest');
const {
Routes
} = require('discord-api-types/v9');
const fs = require('fs');
const config = require('./config.json');
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]
});
const commands = [{
name: 'suggest',
description: 'Submit a suggestion',
options: [{
name: 'suggestion',
description: 'Your suggestion',
type: Constants.ApplicationCommandOptionTypes.STRING,
required: true,
}, ],
}, ];
//register command
const commandsData = commands.map((command) => ({
...command,
type: Constants.ApplicationCommandTypes.CHAT_INPUT,
}));
const rest = new REST({
version: '9'
}).setToken(config.token);
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationGuildCommands(config.appId, config.guildId), {
body: commandsData
},
);
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
client.once('ready', () => {
console.log('Bot is online!');
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;
const {
commandName,
options
} = interaction;
if (commandName === 'suggest') {
const suggestion = options.getString('suggestion');
if (!suggestion) {
return interaction.reply('Please provide a suggestion.');
}
try {
await client.guilds.fetch();
const suggestionChannel = client.channels.cache.get('1134703000020062268');
if (!suggestionChannel || suggestionChannel.type !== 'GUILD_TEXT') {
return interaction.reply('Channel not found or not a text channel.');
}
const userTag = interaction.user.tag;
const embed = new MessageEmbed()
.setTitle('New Suggestion')
.setColor('#FFFFFF')
.addField('Submitter', userTag, true)
.addField('Suggestion', suggestion)
.setFooter(`User ID: ${interaction.user.id} | sID: ${interaction.id} • ${new Date().toLocaleString()}`);
const sentMessage = await suggestionChannel.send({
embeds: [embed]
});
await sentMessage.react('👍');
await sentMessage.react('👎');
return interaction.reply('Your suggestion has been submitted!');
} catch (error) {
console.error(error);
return interaction.reply('An error occurred while processing your suggestion.');
}
}
});
client.login(config.token);