-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
189 lines (160 loc) · 7.15 KB
/
index.js
File metadata and controls
189 lines (160 loc) · 7.15 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Import modules and configure dotenv for environment variables
require('dotenv').config();
const { Client, GatewayIntentBits, SlashCommandBuilder, EmbedBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder, ModalBuilder, InteractionType, REST, Routes } = require('discord.js');
// Create a new client instance
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent],
});
// Load variables from .env
const token = process.env.DISCORD_TOKEN;
const clientId = process.env.DISCORD_CLIENT_ID;
const admId = process.env.ADM_ID;
const suggestionChannelId = process.env.SUGGESTION_CHANNEL_ID;
const submitChannelId = process.env.SUBMIT_CHANNEL_ID;
// Debugging environment variables
console.log('Client ID:', clientId);
console.log('Suggestion Channel ID:', suggestionChannelId);
console.log('Submit Channel ID:', submitChannelId);
console.log('Discord Token:', token);
console.log('User ID:', admId);
// Login the bot
client.login(token).catch((error) => {
console.error('Failed to login:', error);
});
// Event: When the bot is ready
client.once('ready', async () => {
console.log(`Bot is online as ${client.user.tag}! 🥷`);
// Register slash commands globally
const commands = [
new SlashCommandBuilder()
.setName('vcprefere')
.setDescription('Escolha entre duas opções aleatórias.'),
new SlashCommandBuilder()
.setName('sugerir')
.setDescription('Abra o modal para sugerir algo.'),
new SlashCommandBuilder()
.setName('quiz')
.setDescription('Responda a uma pergunta aleatória.'),
];
const rest = new REST({ version: '10' }).setToken(token);
try {
console.log('Registering slash commands globally...');
await rest.put(Routes.applicationCommands(clientId), { body: commands });
console.log('Slash commands registered successfully!');
} catch (error) {
console.error('Error registering commands:', error);
}
});
// Lista de perguntas do comando /vcprefere
const questions = [
'Você prefere isso ou aquilo?',
// ... (adicione mais perguntas no mesmo formato)
];
// Lista de perguntas para o comando /quiz
const quizQuestions = [
{
question: 'Qual é a capital da França?',
options: ['Paris', 'Berlim', 'Londres', 'Roma'],
correct: 1,
},
{
question: 'Qual é o maior planeta do sistema solar?',
options: ['Terra', 'Marte', 'Júpiter', 'Vênus'],
correct: 3,
},
{
question: 'Quem pintou a Mona Lisa?',
options: ['Michelangelo', 'Leonardo da Vinci', 'Van Gogh', 'Picasso'],
correct: 2,
},
// ... (adicione mais perguntas no mesmo formato)
];
// Event: Handle interactions (slash commands and modals)
client.on('interactionCreate', async (interaction) => {
if (interaction.isCommand()) {
const { commandName } = interaction;
// Handle /vcprefere command
if (commandName === 'vcprefere') {
const randomQuestion = preferQuestions[Math.floor(Math.random() * preferQuestions.length)];
const embed = new EmbedBuilder()
.setColor(0x00ae86)
.setTitle('Você prefere? 🤔')
.setDescription(randomQuestion)
.setFooter({ text: 'Vote reagindo abaixo!' });
const message = await interaction.reply({ embeds: [embed], fetchReply: true });
await message.react('1️⃣'); // Option 1
await message.react('2️⃣'); // Option 2
}
// Handle /sugerir command
if (commandName === 'sugerir') {
const modal = new ModalBuilder()
.setCustomId('sugestaoModal')
.setTitle('Envie sua Sugestão');
const suggestionInput = new TextInputBuilder()
.setCustomId('suggestionInput')
.setLabel('Qual é a sua sugestão?')
.setStyle(TextInputStyle.Paragraph)
.setPlaceholder('Digite aqui sua sugestão...')
.setRequired(true);
const actionRow = new ActionRowBuilder().addComponents(suggestionInput);
modal.addComponents(actionRow);
await interaction.showModal(modal);
}
// Handle /quiz command
if (commandName === 'quiz') {
const randomQuiz = quizQuestions[Math.floor(Math.random() * quizQuestions.length)];
const embed = new EmbedBuilder()
.setTitle('📚 Quiz')
.setDescription(randomQuiz.question)
.addFields(
randomQuiz.options.map((option, index) => ({
name: `\`${index + 1}\`. ${option}`,
value: '\u200B',
}))
)
.setColor(0x00ae86)
.setFooter({ text: 'Responda com o número da alternativa (1, 2, 3 ou 4).' });
const message = await interaction.reply({
embeds: [embed],
fetchReply: true,
});
const filter = (response) =>
['1', '2', '3', '4'].includes(response.content) &&
response.author.id === interaction.user.id;
const collector = message.channel.createMessageCollector({
filter,
time: 20000,
max: 1,
});
collector.on('collect', (response) => {
const answer = parseInt(response.content, 10);
if (answer === randomQuiz.correct) {
response.reply('🎉 Parabéns! Você acertou!');
} else {
response.reply(`❌ Resposta errada! A resposta correta era \`${randomQuiz.correct}\`.`);
}
});
collector.on('end', (collected) => {
if (collected.size === 0) {
message.channel.send(`⏰ O tempo acabou! A resposta correta era \`${randomQuiz.correct}\`.`);
}
});
}
}
// Handle modal submissions
if (interaction.type === InteractionType.ModalSubmit && interaction.customId === 'sugestaoModal') {
const suggestion = interaction.fields.getTextInputValue('suggestionInput');
const submitChannel = client.channels.cache.get(submitChannelId);
if (!submitChannel) {
return interaction.reply({ content: 'Não consegui encontrar o canal para enviar a sugestão.', ephemeral: true });
}
const embed = new EmbedBuilder()
.setColor(0x00ae86)
.setTitle('Nova Sugestão 💡')
.setDescription(suggestion)
.setFooter({ text: `Enviado por ${interaction.user.tag}`, iconURL: interaction.user.displayAvatarURL() })
.setTimestamp();
await submitChannel.send({ embeds: [embed] });
await interaction.reply({ content: 'Sua sugestão foi enviada com sucesso! 🎉', ephemeral: true });
}
});