-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
64 lines (57 loc) · 1.86 KB
/
bot.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
const { Client, GatewayIntentBits, REST, Routes } = require('discord.js');
const axios = require('axios');
const config = require('./config.json');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.MessageContent] });
const commands = [
{
name: "kur",
description: "Kur görüntüleme",
options: [
{
name: "doviz",
description: "Döviz birimi",
type: 3,
required: true
}
]
}
];
const rest = new REST({ version: '10' }).setToken(config.token);
(async () => {
try {
await rest.put(Routes.applicationCommands(config.clientID), { body: commands });
console.log("Komutlar yükleniyor...");
console.log("Bot aktif!");
} catch (error) {
console.error(error);
}
})();
client.on('interactionCreate', async (interaction) => {
if (interaction.isCommand()) {
if (interaction.commandName === "kur") {
const exchange = interaction.options.getString('doviz').toUpperCase();
const exchangeRate = await getExchangeRate();
if (exchangeRate.hasOwnProperty(exchange)) {
const rate = exchangeRate[exchange];
const embed = {
title: `${exchange} Kuru`,
description: `Alış: ${rate.Alış} \n Satış: ${rate.Satış} TL\nDeğişim: ${rate.Değişim}`,
color: 0x57F287
};
interaction.reply({ embeds: [embed], ephemeral: true});
} else {
interaction.reply('Böyle bir kur bulunamadı.', { ephemeral: true });
}
}
}
});
async function getExchangeRate() {
try {
const response = await axios.get("https://finans.truncgil.com/today.json");
return response.data;
} catch (error) {
console.error(error);
return null;
}
}
client.login(config.token);