Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Discord Bot - MySQL

Lezetho

Moderator
Staff member
Mod
Joined
Oct 28, 2023
Messages
270
SneakyHub has a built in MySQL and MariaDB support!

Create the Database​

Go to the selected SneakyHub Panel Server, and click on the Databases tab. Here, we want to press New Database
spaces%2F-MbMPVcjP3kdnf2myIpw%2Fuploads%2F7l0JiBBRDWuzmnXikiHv%2Fimage.png

Name you database anything, but DO NOT PUT ANYTHING FOR CONNECTIONS FROM TAB. That will make it so your Discord Bot cannot access the database.

spaces%2F-MbMPVcjP3kdnf2myIpw%2Fuploads%2F52ppWFn4ejrhvWvIuhKD%2Fimage.png

After, you'll see that the database home has been updated. Press the EYE button to find the connection details.


spaces%2F-MbMPVcjP3kdnf2myIpw%2Fuploads%2F9tMDpV0dtk7k4MUJB6qZ%2Fimage.png

You've now created your database successfully.


Connecting to your Discord Bot ( Discord.js )​

We're going to use the MySQL package to connect your Discord Bot to our database.
spaces%2F-MbMPVcjP3kdnf2myIpw%2Fuploads%2F1xeMuZ5DrjZ4qoMSRdvg%2Fimage.png

After, go into your bots code, and somewhere in your code enter this:

const mysql = require('mysql'); const db = mysql.createConnection({ host: '10.10.12.243', user: 'your_username', // your database username, required password: 'your_password', // the database password that was generated, required database: 'your_database', // what you named your database, required }); db.connect((err) => { if (err) { console.error('Error connecting to MySQL:', err); } else { console.log('Connected to MySQL database'); } });

Fill out the rest of the rest of the required fields. After, you can start your bot and it should successfully say, Connected to MySQL database.
 
Back
Top