-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.js
50 lines (40 loc) · 1.33 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
require('dotenv').config();
const { Client, GatewayIntentBits } = require('discord.js');
var Airtable = require('airtable');
var base = new Airtable({ apiKey: process.env.AIRTABLE_ACCESS_TOKEN }).base(process.env.BASE_ID);
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
]
});
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('messageCreate', async message => {
if (message.author.bot) return;
if (message.content === '!xps') {
message.channel.send(`Loading the data ⏳ `);
let allRecords = '';
base('Table 1').select({
view: "XP Leaderboard"
}).eachPage(function page(records, fetchNextPage) {
records.forEach(function (record) {
const name = record.get('Name');
const xp = record.get('XP');
if (name && xp) {
allRecords += ` 🔥 ${name} : ${xp}\n`;
}
});
fetchNextPage();
}, function done(err) {
if (err) {
console.error(err);
return;
}
message.channel.send(`${allRecords}`);
});
}
});
client.login(process.env.BOT_TOKEN);