-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
114 lines (83 loc) · 3.07 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
113
114
const fs = require('fs');
const { Client, Collection, Intents, Message } = require("discord.js");
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
const { token, prefix } = require("./config.json");
const meme = require('./commands/meme');
const userinfo = require('./commands/userinfo');
const config = require("./config.json");
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.DIRECT_MESSAGES, Intents.FLAGS.GUILD_VOICE_STATES] });
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
const queue = new Map();
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.data.name, command);
}
client.on("ready", () => {
console.log("Bot loaded")
});
//event handling and prefix command handling
//client.config = config;
//fs.readdir("./events/", (err, files) => {
// if (err) return console.error(err);
// files.forEach(file => {
// const event = require(`./events/${file}`);
// let eventName = file.split(".")[0];
// client.on(eventName, event.bind(null, client));
// });
//});
//client.komennot = new Collection();
//fs.readdir("./komennot/", (err, files) => {
// if (err) return console.error(err);
// files.forEach(file => {
// if (!file.endsWith(".js")) return;
// let props = require(`./komennot/${file}`);
// let commandName = file.split(".")[0];
// console.log(`Attempting to load command ${commandName}`);
// client.komennot.set(commandName, props);
// });
//});
//slash command handling
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
});
//some random shit
client.on("messageCreate", async message => {
console.log(`${message.author.username}: ${message.content} in: ${message.guild}`)
fs.appendFile('./log.txt', `${message.author.username}: ${message.content} in: ${message.guild}\n`, err => {
if (err) {
console.error(err)
return
}
})
})
client.on('interactionCreate', interaction => {
if (!interaction.isButton()) return;
if (interaction.customId === "memebutton") {
request("https://meme-api.herokuapp.com/gimme", function(meme_url){
interaction.channel.send(meme_url)
})
}
});
function request(url, callback) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.addEventListener('load', function() {
resolve(xhr);
const obj = JSON.parse(xhr.responseText);
return callback(obj.url)
});
xhr.addEventListener('error', reject);
xhr.open('GET', url, true);
xhr.send();
});
}
client.login(token)