-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
55 lines (46 loc) · 1.36 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
const mysql = require('mysql');
const { Client, IntentsBitField } = require('discord.js');
require('dotenv/config');
// Discord bot credentials
const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.MessageContent,
],
});
// MySQL database credentials
const db = mysql.createConnection({
host: 'ryuga',
user: 'Ryuga',
password: process.env.PASSWORD ,
database: 'Ryu'
});
// Connect to MySQL database
db.connect((err) => {
if (err) throw err;
console.log('Connected to MySQL database');
});
// Discord bot ready event
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});
client.on("interactionCreate", (interaction) => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === "show") {
const id = interaction.options.get("id").value;
const sql = 'SELECT * FROM images WHERE id = ?';
db.query(sql, [id], (err, results) => {
if (err) throw err;
if (results.length > 0) {
const url = results[0].url;
interaction.reply(url);
} else {
interaction.reply(`Image with ID ${id} not found.`);
}
});
}
});
// Log in to Discord bot
client.login(process.env.TOKEN);