-
Notifications
You must be signed in to change notification settings - Fork 0
/
discordbot.js
67 lines (67 loc) · 2.19 KB
/
discordbot.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
import { Client, Events, GatewayIntentBits } from 'discord.js';
import { Build, Api } from 'discordwebclient';
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessages] });
let i = null;
//let a : Api|null = null;
client.once(Events.ClientReady, async (c) => {
console.log(`Ready! Logged in as ${c.user.tag}---${c.user.id}`);
if (i === null) {
i = await new Build();
i.setApis(["/test", "/t"]);
i.setEngine("express");
i.setPort(3000);
i.build();
}
// if(a===null){
// a = await new Api();
// }
});
client.on("messageCreate", async (message) => {
if (message.content === "logs") {
const logs = i?.getlogs();
const arrayMessage = [];
for (const log of logs || []) {
arrayMessage.push(log);
}
message.reply({ content: arrayMessage.join("\n") });
console.log(logs);
}
if (message.content === "apis") {
const apis = i?.getApis() || [];
const arrayMessage = [];
for (const api of apis) {
arrayMessage.push(api);
}
message.reply({ content: arrayMessage.join("\n") });
}
if (message.content.startsWith("send")) {
const args = message.content.split(" ");
console.log(args);
console.log("Sending to :" + args[1]);
const a = await new Api();
const testData = {
api: args[1],
guild: message.guild?.name,
channel: message.channel.id,
user: message.author.id
};
a.setData({ test: testData });
a.setMessage("This is a test message Check Status 200 OK");
a.setStatus(200);
a.send(args[1]);
message.reply("sent");
}
if (message.content.startsWith("receive")) {
const a = await new Api();
const args = message.content.split(" ");
console.log(args);
console.log("Receiving from :" + args[1]);
a.receive(args[1]);
message.reply("received");
}
if (message.content === "clear") {
i?.clearlogs();
message.reply("Logs have been cleared");
}
});
client.login('Your Token Here');