-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.js
More file actions
74 lines (63 loc) · 2.6 KB
/
functions.js
File metadata and controls
74 lines (63 loc) · 2.6 KB
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
// General-use Functions //
const { EmbedBuilder } = require("discord.js");
const https = require("https");
const fetch = require("node-fetch");
const { resolve } = require("path");
f = {
sendError: async function sendError(value, interaction) { // Sends value in code block to Discord
const errorEmbed = new EmbedBuilder()
.setColor(embedRed)
.addFields({ name: "An error occured!", value: `\`\`\`${value}\`\`\`` });
await interaction.reply({embeds: [errorEmbed]});
},
sendConsole: async function sendConsole(title, value, color, interaction, type) { // Sends value in code block to Discord
const errorEmbed = new EmbedBuilder()
.setColor(color)
.addFields({ name: title, value: `\`\`\`${value}\`\`\`` });
if(type == "reply") {
await interaction.reply({embeds: [errorEmbed]});
}
if(type == "message") {
await interaction.channel.send({embeds: [errorEmbed]});
}
},
sendEmbed: async function sendEmbed(string1, string2, color, interaction, type) { // Sends basic embed
const embed = new EmbedBuilder()
.setColor(color)
.addFields({ name: string1, value: string2 });
if(type == "reply") {
await interaction.reply({embeds: [embed]});
}
if(type == "message") {
await interaction.channel.send({embeds: [embed]});
}
},
sendMessage: async function sendMessage(string, color, interaction, type, ep) { // Sends one-line embed
const embed = new EmbedBuilder()
.setColor(color)
.setDescription(string);
if(type == "reply") {
await interaction.reply({embeds: [embed], ephemeral: ep});
}
if(type == "message") {
await interaction.channel.send({embeds: [embed]});
}
},
capitalize: async function capitalize(string) {
return string[0].toUpperCase()+string.slice(1);
},
twoDigits: async function twoDigits(input) { // 6 -> 06, 12 -> 12
return(input.length < 2 ? "0"+input : input);
},
getJSON: async function getJSON(url) {
let data = fetch(url)
.then(res => res.json())
.then(json => { return json; });
return data;
},
time: async function time(date, interaction) {
const locale = interaction.guild.preferredLocale;
const options = { year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit', timeZoneName: 'short' };
return date.toLocaleString(locale, options);
}
}