Skip to content

Instantly share code, notes, and snippets.

@Pkmmte
Last active October 1, 2024 07:39
Show Gist options
  • Save Pkmmte/d3ee3604e82352f08a02ce76c3a5068e to your computer and use it in GitHub Desktop.
Save Pkmmte/d3ee3604e82352f08a02ce76c3a5068e to your computer and use it in GitHub Desktop.
πŸ›  Discord Activity Entry Command Fix

πŸ›  Discord Activity Entry Command Fix

Got a fancy new Discord Activity but found that your Launch button went missing? Here's a patch for that!

Running the Script

Make sure you have Node.js installed and download (or copy) the script below, then run this in your terminal:

node discord-activity-entry-fix.js <DISCORD_CLIENT_ID> <DISCORD_TOKEN>

Replace <DISCORD_CLIENT_ID> and <DISCORD_TOKEN> with the actual values in your Discord Developer Portal. Yes, you need a Discord Bot token to fix your Discord Activity.

This will work even if you're making Discord Apps using other languages, such as Python or Ruby.

@robojs/patch

Using Robo.js to build your Discord Activities? You're can install @robojs/patch to fix this instantly.

npx robo add @robojs/patch

That's it, seriously! It's a Robo Plugin, so it's integrated instantly. Just make sure to have both DISCORD_CLIENT_ID and DISCORD_TOKEN environment variables set in your .env file.

This method is recommended for those using Robo.js to build their Discord Activities. If you're not already using Robo.js, we highly recommend you check it out!

Discord Activities are Fun!

Discord Activities are a fun way to engage with your community. They're like mini-games or interactive experiences that you can create and share with others and are often built using HTML, CSS, and JavaScript. They're essentially web apps that run inside Discord itself. Robo.js is a powerful framework that makes building Discord Activities easy and fun.

npx create-robo <projectName> -k activity

If you don't already have a Discord Activity, you can create one in seconds with Robo.js.

Don't let a missing launch button ruin your day. Use one of the methods above to fix your Discord Activity and get back to building awesome experiences for your community. Please share this gist with others who might find it useful!

You can join our Discord Server to chat with other developers, ask questions, and share your projects. We're a friendly bunch and always happy to help! Plus, our very own AI Robo, Sage, is there to assist you with any questions you may have.

Happy coding! ✨

// Set this to true if you run into issues or want to see app data logged.
const Debug = false
// Set this as your Discord Bot Token and Client ID if you don't want to pass them as arguments.
const BotToken = ''
const ClientId = ''
// Runs this script.
start().then(console.log).catch(console.error)
/**
* Fixes the Entry Command in your Discord App.
*
* Run this in your terminal:
* ```bash
* node discord-activity-entry-fix.js <DISCORD_CLIENT_ID> <DISCORD_TOKEN>
* ```
*
* Replace `<DISCORD_CLIENT_ID>` and `<DISCORD_TOKEN>` with the actual values in your [Discord Developer Portal](https://discord.com/developers/applications/).
*/
async function start() {
// Get the client ID and token from arguments or hard-coded values above.
const clientId = process.argv[2] || ClientId
const token = process.argv[3] || BotToken
if (!clientId || !token) {
throw '❌ Please provide the Discord Client ID and Token.\n\nUsage:\nnode discord-activity-entry-fix.js <DISCORD_CLIENT_ID> <DISCORD_TOKEN>'
}
// Get the existing commands.
const commandsResponse = await request('/commands', { clientId, token })
const commands = await commandsResponse.json()
loggerDebug('Existing commands:', commands)
if (!commandsResponse.ok) {
throw '❌ Error fetching commands. ' + commands.message
}
// See if an entry command already exists.
let entryCommand = commands.find((command) => command.type === 4)
if (entryCommand) {
loggerDebug('Entry command:', entryCommand)
return 'πŸŽ‰ Entry command already exists. No need to fix.'
}
// Create the entry command if it doesn't exist.
const body = {
name: 'launch',
description: 'Launch an activity',
contexts: [0, 1, 2],
integration_types: [0, 1],
type: 4,
handler: 2
}
const commandResponse = await request.post('/commands', { body, clientId, token })
entryCommand = await commandResponse.json()
loggerDebug('Created command response:', entryCommand)
if (entryCommand.errors) {
throw '❌ Error creating entry command.'
}
return 'πŸŽ‰ Successfully registered entry command.'
}
function loggerDebug(...message) {
if (Debug) {
console.log('πŸ›', ...message)
}
}
function request(path, options) {
const { body, clientId, method = 'GET', token } = options
return fetch('https://discord.com/api/v10/applications/' + clientId + path, {
body: body ? JSON.stringify(body) : undefined,
headers: {
Authorization: 'Bot ' + token,
'Content-Type': ['POST', 'PUT'].includes(method) ? 'application/json' : undefined
},
method: method
})
}
request.post = (path, options) => request(path, { ...options, method: 'POST' })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment