GithubHelp home page GithubHelp logo

jjsdjsdadasds / discord-interactions-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from liba001/discord-interactions-example

0.0 0.0 0.0 212 KB

An example on how to use Discord Interactions (Slash Commands)

Home Page: https://discord.com

License: MIT License

Python 98.32% Dockerfile 1.68%
discord-bot

discord-interactions-example's Introduction

Discord Interactions

This repository is an example for how to make Discord Interactions (or more specifically Slash Commands) work via outgoing webhook as opposed to the websocket gateway.

This example uses Python and the discord-interactions.py library's Flask extension. To make a URL available to Discord, the code is built into a Docker image and then hosted in a container on Google Cloud Run, which is a serverless cloud platform. Cloud Run will automatically generate a URL which can be used to call the service. This URL then needs to be put in the "Interactions Endpoint URL" field on the application's page on the Discord Developer Portal.

./assets/Interactions_Endpoint_URL.png

File Structure

In this example, there are three files that contain our Python code.

main.py

This file contains all the commands' logic and the required setup for Flask. It gets run as the entrypoint to our application.

commands.py

Here, we define the structure of our commands using discord-interaction.py's Object-Command Mapper. The command classes get imported by main.py and register_commands.py.

register_commands.py

In order to separate the registration of our commands and the actual execution of our app, we take care of the former in this file. What happens here is that we tell Discord about our commands and their structure so they can be recognised by Discord and we get that neat autocompletion in the Discord client. That also means, that this file needs to be executed separately from main.py to make the commands be callable from Discord in the first place. It only needs to be run once when you first setup the commands and then everytime you change something about a command's structure.

Note: It takes up to one hour after registration for global commands to be available for use. If you want to have commands available instantly for testing purposes or if you only want them to be available on one Discord Server, you can use guild commands. Read more about global and guild commands.

Invite the demo bot!

I have created a demo bot that you can invite to your Discord server to test Discord Interactions. It is automatically updated to run the latest version of the code in this repository.

Note: As you can see, the bot only requires the applications.commands scope for Slash Commands to be available. No actual bot user gets added to your Discord server.

discord-interactions-example's People

Contributors

liba001 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.