This project implements a Discord bot using Python and the discord.py
library. The bot acts as a command execution and shell interaction tool within a designated Discord text channel. Users can execute commands, navigate the file system, and receive command output directly in the Discord channel.
Follow the steps below to install and run the Discord Shell Bot on Linux:
- Python and pip should be installed on your Linux system.
- Git should be installed to clone the repository.
-
Open your terminal and navigate to the directory where you want to clone the repository.
-
Run the following command to clone the repository:
git clone https://github.com/Newer1107/termtodiscord
-
Navigate to the cloned repository:
cd termtodiscord
-
Create a new virtual environment using the following command:
python -m venv .
-
Activate the virtual environment by running the following command:
source bin/activate
-
Install the required dependencies by running the following command:
pip install -r requirements.txt
-
Rename the
.env.example
file to.env
:mv .env.example .env
-
Open the
.env
file and update the following lines:BOT_TOKEN=<your bot token> OWNER_ID=<your Discord ID> CHANNEL_ID=<your channel ID> LOG_FILE_LOCATION=<path to the log file>
- Replace
<your bot token>
with the token of your Discord bot. - Replace
<your Discord ID>
with your own Discord ID (to make sure only you can execute console commands). - Replace
<your channel ID>
with the ID of the Discord channel where you want the bot to operate. - Replace
<path to the log file>
with the desired location for the log file. For example:/home/logs.txt
.
- Replace
- If you want to change the starting directory for the bot's file system navigation, modify the
current_directory
variable in the code to the desired directory path.
- You have the option to add a thumbnail image to the embedded system information message. To do this, follow the steps below:
- Prepare an image file (e.g.,
arch.png
) that you want to use as the thumbnail. - Copy the image file to the
termtodiscord
directory. - Open
bot.py
in a text editor. - Find the line
arch_logo = File("ADD-IMAGE-PATH-HERE")
. - Replace
"ADD-IMAGE-PATH-HERE"
with the actual path to the image file. For example:arch_logo = File("arch.png")
.
- Prepare an image file (e.g.,
- Visit the Discord Developer Portal.
- Click on the "New Application" button.
- Enter a name for your application (this will be the name of your bot).
- Click the "Create" button.
- In the application dashboard, navigate to the "Bot" tab on the left sidebar.
- Click on the "Add Bot" button.
- A confirmation prompt will appear. Click "Yes, do it!" to proceed.
- Customize your bot's display name and profile picture by adjusting the "Username" and "Avatar" settings under the "Bot" tab.
- Toggle the "Public Bot" switch if you want your bot to be available publicly.
- Enable the necessary bot permissions under the "Bot Permissions" section. These permissions define what your bot can do on Discord servers.
- Scroll down and click the "Save Changes" button.
- Under the "Token" section, click the "Copy" button to copy the bot token. This token is a secret key that identifies your bot to Discord.
- Important: Treat the bot token as sensitive information and keep it private. Do not share it publicly or include it in your code repository.
- Navigate to the "OAuth2" tab on the left sidebar.
- In the "Scopes" section, select the necessary bot permissions based on your bot's functionality.
- Copy the generated OAuth2 URL.
- Open a new browser tab and paste the URL.
- Choose the server where you want to invite the bot and follow the prompts to complete the invitation process.
-
Start the bot by running the following command:
python bot.py
- In the designated text channel (specified by
CHANNEL_ID
in the.env
file), type commands to interact with the bot. - Use the
ping
command to check if the bot is responding. Example:!ping
- Use the
hello
command to receive a greeting from the bot. Example:!hello
- Execute shell commands directly by typing them in the channel. Only the bot owner, specified by
OWNER_ID
in the.env
file, can execute console commands. - The bot will execute the command, capture the output, and display it in a formatted message.
- Use the
cd
command followed by a directory path to navigate the file system. Example:cd /home/user/Downloads
- To ensure security and prevent exposing sensitive information, make sure to keep the
.env
file private and exclude it from version control (if any). - Feel free to modify and customize the code according