cerebrus6 / discord_bot_sandbox

Discord bot experimentation using node js.

Home Page:https://discord-bot-cerebrus6.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

discord.js is required to make a discord bot

axios is used to create XMLHttpRequests

mysql2 is used to make asynchronous queries to the database

The Client Token should be put in the .env file. It should not be shared publicly, make sure to ignore it when commiting to git. CLIENT_TOKEN=yourKey

process.env.CLIENT_TOKEN is used to access the content of the local file "env" and accessing the CLIENT_TOKEN variable

One of the challenges I've encountered on this personal project is querying asynchronously to a database.

Solution:

First step is to install and require mysql2/promise

	npm:	npm install -g mysql2

			npm link mysql2

Second is to create an async function with this content

	script:	const mysql = require("mysql2/promise");

			const connection = mysql.createConnection({

				host: "",

				user: "",

				password: "",

				database: "",

			})

			let [rows, fields] = await connection.execute("SELECT * FROM table WHERE name = ? OR name = ?", ["James", "Bond"])

			return rows;

Make sure to call this function within an asynchronous scope, else it will only return a promise without a value.

About

Discord bot experimentation using node js.

https://discord-bot-cerebrus6.vercel.app


Languages

Language:JavaScript 100.0%