The new bot-hosting.net API is live
Something people might have missed is the new API for bot-hosting.net is live. Therefor I made this slash command just like for the previous API. Enjoy the new goodies you all!
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
const {
SlashCommandBuilder,
ApplicationIntegrationType,
InteractionContextType,
MessageFlags,
PermissionFlagsBits,
} = require("discord.js");
// Or handle the botDeployId and botServerApiKey in your own way. They API key for this example needs deployments:read and deployments:power scopes.
const { botDeployId, botServerApiKey } = require("../../../config.json");
// Full options see: https://bot-hosting.net/developer
module.exports = {
data: new SlashCommandBuilder()
.setName("botserver")
.setDescription("Options for you bot server API.")
.addStringOption((option) =>
option
.setName("action")
.setDescription("Select action to perform.")
.setRequired(true)
.addChoices(
{ name: "Info", value: "info" },
{ name: "Start", value: "start" },
{ name: "Restart", value: "restart" },
{ name: "Stop", value: "stop" },
{ name: "Kill", value: "kill" },
),
)
.setIntegrationTypes([ApplicationIntegrationType.GuildInstall])
.setContexts([InteractionContextType.Guild])
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
async execute(interaction) {
const action = interaction.options.getString("action");
// info
if (action == "info") {
const resp = await fetch(
`https://bot-hosting.net/api/v1/deployments/${botDeployId}`,
{
method: "GET",
headers: { Authorization: `Bearer ${botServerApiKey}` },
},
);
const data = await resp.json();
const sent = await interaction.reply({
content: `\`\`\`json\n${JSON.stringify(data, null, 2)}\n\`\`\``,
withResponse: true,
flags: MessageFlags.Ephemeral,
});
}
//info
// start / restart / stop
if (
action == "start" ||
action == "restart" ||
action == "stop" ||
action == "kill"
) {
const resp = await fetch(
`https://bot-hosting.net/api/v1/deployments/${botDeployId}/power`,
{
method: "POST",
headers: {
Authorization: `Bearer ${botServerApiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ action: action }),
},
);
const data = await resp.json();
const sent = await interaction.reply({
content: `\`\`\`json\n${JSON.stringify(data, null, 2)}\n\`\`\``,
withResponse: true,
flags: MessageFlags.Ephemeral,
});
}
// start / restart / stop
},
};
This post is licensed under CC BY 4.0 by the author.