-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
71 lines (65 loc) · 2.14 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
const express = require('express')
const app = express()
const ms = require('pretty-ms')
app.get('/', (req , res) => {
res.send("ok")
})
app.listen(process.env.PORT || 3000)
const fetch = require('node-fetch')
const { Client, Collection } = require("discord.js")
const client = new Client({
intents: ["GUILDS",
"GUILD_MESSAGES",
"GUILD_MESSAGE_REACTIONS",
"GUILD_MESSAGE_TYPING",
"DIRECT_MESSAGES",
"DIRECT_MESSAGE_REACTIONS",
"DIRECT_MESSAGE_TYPING"],
partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
restTimeOffset: 0,
allowedMentions: {
parse: ['users']
}
})
client.on("ready", () => {
console.log("Bot is ready for notebin creation")
})
client.on("messageCreate", async (message) => {
if(message.author.bot) return;
if(message.content.toLowerCase() === ".ping") {
const l = await message.channel.send('Pinging...')
const ping = l.createdTimestamp - message.createdTimestamp
await l.edit(`Pong! (Websocket: ${client.ws.ping}ms. Roundtrip: ${ping}ms.)`)
}
if(message.content.toLowerCase() === ".uptime") {
return message.channel.send(`I have been running for: ${ms(client.uptime)}`)
}
if(message.content.toLowerCase() === ".help") {
return message.channel.send("**Commands**\n `.ping`, `.uptime`, `.help`, `.codebin`")
}
const args = message.content.split(" ").slice(1)
if(message.content.toLocaleLowerCase().startsWith(".codebin")) {
const text = args.join(" ")
if(!text) return message.channel.send("Please provide a text.")
try {
const create = await fetch('https://notebin.cf/api/create', {
method: 'POST',
body: JSON.stringify({text: text}),
headers: {
"Content-Type": "application/json"
}
}).then(response => response.json()).then(async(data) => {
if(data.url) {
return message.channel.send(`Saved text to: ${data.url}`)
} else {
message.channel.send(`Something went wrong!`)
return console.log(JSON.stringify(data.error[0].msg) || data)
}
})
} catch(e) {
console.log(e)
message.channel.send("Error Occured")
}
}
})
client.login(process.env.token)