Skip to content

Instantly share code, notes, and snippets.

@kipBO
Created January 8, 2026 15:22
Show Gist options
  • Select an option

  • Save kipBO/fa798b7d6cc0acd05403b642cb3b9bd9 to your computer and use it in GitHub Desktop.

Select an option

Save kipBO/fa798b7d6cc0acd05403b642cb3b9bd9 to your computer and use it in GitHub Desktop.
Discord.js basic Bot-Hosting.net server API slash commands
const { SlashCommandBuilder, MessageFlags, AttachmentBuilder } = require('discord.js')
const { botServerId, botServerApiKey } = require('../config.json') // Or handle the botServerId and botServerApiKey in your own way
// Full options see: https://api.ptero.sh/#/ and https://bot-hosting.net/
module.exports = {
data: new SlashCommandBuilder()
.setName('botserver')
.setDescription('Manage your bot server.')
.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' },
),
)
.setDefaultMemberPermissions(0),
async execute(interaction) {
const action = interaction.options.getString('action')
// info
if (action == 'info') {
fetch(`https://control.bot-hosting.net/api/client/servers/${botServerId}`, {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': `Bearer ${botServerApiKey}`,
},
}).then((response) => {
return response.json()
}).then((json) => {
const output = JSON.stringify(json, null, 2)
if (output.length > 1900) {
const attachment = new AttachmentBuilder(Buffer.from(output), { name: 'response.json' })
return interaction.reply({ files: [attachment], flags: MessageFlags.Ephemeral })
}
return interaction.reply({ content: `\`\`\`json\n${output}\n\`\`\``, flags: MessageFlags.Ephemeral })
});
}
//info
// start / restart / stop
if (action == 'start' || action == 'restart' || action == 'stop') {
fetch(`https://control.bot-hosting.net/api/client/servers/${botServerId}/power`, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': `Bearer ${botServerApiKey}`,
},
body: JSON.stringify({signal: action})
}).then((response) => {
if(response.status !== 204){
return interaction.reply({ content: `Error: ${response.status}`, flags: MessageFlags.Ephemeral })
} else {
return interaction.reply({ content: `Action: ${action} complete.`, flags: MessageFlags.Ephemeral })
}
});
}
// start / restart / stop
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment