This is a simple Discord bot that connects to a MySQL database and responds to user requests to display images stored in the database.
- A Discord account
- A Discord server where you have permission to add a bot
- A MySQL database with at least one table that contains image URLs and corresponding IDs
- Node.js and npm installed on your computer
- Clone this repository to your local machine
- Install the required dependencies by running
npm install
- Create a
.env
file in the root directory of the project with the following variables: - Update the
db
constant inindex.js
with your MySQL database credentials: - Create a table in your MySQL database to store your images. The table should have at least two columns:
id
andurl
. - Insert some images into the database with their corresponding IDs.
PASSWORD=your_mysql_password
TOKEN=your_discord_bot_token
GUILD_ID=your_channel_id
CLIENT_ID=your_bot_application_id
Replace your_mysql_password
with the password for your MySQL database, and your_discord_bot_token
with the token for your Discord bot. You can obtain a bot token by creating a new bot application in the Discord developer portal.
const db = mysql.createConnection({
host: 'your_mysql_host',
user: 'your_mysql_username',
password: process.env.PASSWORD,
database: 'your_mysql_database_name'
});
Replace your_mysql_host
, your_mysql_username
, and your_mysql_database_name
with your MySQL database information.
To run the bot, use the command npm start
. The bot will connect to your Discord server and listen for user requests to display images. Users can request an image by typing !show <id>
in the chat, where <id>
is the ID of the image they want to display.
If you have any suggestions or find any bugs, please feel free to open an issue or submit a pull request.