Coded for Discord Bot that allows users to execute and beautify code in Python, JavaScript, HTML, CSS, Java, and Ruby.
This bot listens for messages in Discord. If a message starts with !code
, it extracts the code from the message. It determines the programming language of the code based on the first line of the code. Depending on the language, the bot will either execute the code or beautify and highlight it before sending it back to the user.
- Python
- JavaScript
- HTML/CSS
- Java
- Ruby
- Create a Discord bot and get its token.
- Install the necessary Python libraries (
discord
,jsbeautifier
,js2py
,pygments
,requests
,urllib
,python-dotenv
,keep_alive
). - Replace the placeholder values for
CLIENT_ID
andCLIENT_SECRET
with your own values (if you want to use the Java feature). - Save the code as a Python file and run it.
- The bot will start listening for messages in Discord. When a user types
!code
, followed by their code, the bot will execute or beautify the code based on its programming language, and send the output back to the user.
To run this bot, you will need:
- A Discord bot token
- Python 3.6 or higher
- The following Python libraries:
discord
jsbeautifier
js2py
pygments
requests
urllib
python-dotenv
keep_alive
The following configuration variables can be set in the .env
file:
DISCORD_TOKEN
: Your Discord bot token.CLIENT_ID
: Your JDoodle API client ID (for Java and Ruby).CLIENT_SECRET
: Your JDoodle API client secret (for Java and Ruby).
#!python
used for the Python Language//
used for the Javascript Language<html
used for the HTML Language<style
used for the CSS Languageimport
used for the Java Language!ruby
used for the Ruby Language
!code #!python print("Hello, World!")
- Executes a Python code and prints "Hello, World!" to the console.!code // console.log("Hello, World!")
- Evaluates a JavaScript code and logs "Hello, World!" to the console.!code <html <html><head><title>Test</title></head><body><h1>Hello, World!</h1></body></html>
- Beautifies and highlights an HTML code.!code import public class Main {public static void main(String[] args) {System.out.println("Hello, World!");}}
- Compiles a Java code and prints "Hello, World!" to the console.
Code Execution Bot is licensed under the MIT License. See LICENSE
for more information.
I hope