20
loading...
This website collects cookies to deliver better user experience
+ // This line should be added to your code
- // This line should be removed from your code
A lightweight NodeJS Discord Library.
A Discord command framework for Javascript and Typescript.
New Application
button on the top right corner.Create
.Bot
and click on Add Bot
, and then click Click on Yes, do it!
.TOKEN
section, click Copy
.package.json
.
mkdir <your-project-name>
cd <your-project-name>
npm init
main
in your package.json
is set to index.js
.npm i eris yuuko dotenv
npm i eris yuuko dotenv --save
nodemon
as well.npm i -g nodemon
.env
and index.js
file, and a commands
and events
folder.bufferutil
, zlib-sync
or abalabahaha/erlpack
npm i eslint -D
# -D is short for --save-dev
npx eslint --init
# Just answer the prompts
| .env
│ index.js
│ package-lock.json
│ package.json
│
├───commands
├───events
└───node_modules
│ ...
.env
file with the following:TOKEN=<your-token-here>
PREFIX=<your-bot-prefix>
<your-token-here>
with the Bot token you obtained earlier, and <your-bot-prefix>
with your bot prefix.dotenv
and .env
files,index.js
file, and insert the following at the top to require the packages.const { Client } = require('yuuko'); // Imports the Client constructor
const path = require('path'); // For joining paths
require('dotenv').config(); // Imports the variables in the `.env` file
Client
constructor from Yuuko
but not the Command
constructor. Why? We will be putting the commands in js
files in the command
folder, so our index.js
file will not be crowded with commands. Neat!const bot = new Client({
token: process.env.TOKEN,
prefix: process.env.PREFIX,
ignoreBots: true,
});
ignoreBots: true
in the code tells our bot to ignore all messages sent by other bots.bot.globalCommandRequirements = {
guildOnly: true,
};
bot.globalCommandRequirements = {
dmOnly: true,
};
index.js
by doingbot.extendContext({
variableOne: 'Variable number 1!',
});
context.<variable-name>.
bot
.addDir(path.join(__dirname, 'commands'))
.addDir(path.join(__dirname, 'events'))
.connect();
index.js
file should now look something like this:const { Client } = require('yuuko');
const path = require('path');
const dotenv = require('dotenv');
var env = dotenv.config();
env = process.env;
const bot = new Client({
token: env.TOKEN,
prefix: env.PREFIX,
ignoreBots: true,
});
bot.extendContext({
variableOne: 'Variable number 1!',
});
bot.editStatus('dnd'); // edits bot status
bot.on('error', (err) => {
console.error(err);
});
bot.globalCommandRequirements = {
guildOnly: true,
};
bot
.addDir(path.join(__dirname, 'commands'))
.addDir(path.join(__dirname, 'events'))
.connect();
./events
and name it ready.js
.const { EventListener } = require('yuuko');
module.exports = new EventListener('ready', (context) => {
// context.client = bot
console.log(`Logged in as ${context.client.user.usename}`);
});
module.exports = new EventListener('ready', ({client}) => {
// client = bot
console.log(`Logged in as ${client.user.usename}`);
});
context
. You may be thinking:client
variable in bot.extendContext({})
! Why can it be used here?'client
as the bot
, so you do not need to worry about it!nodemon .
ready.js
code:const { EventListener } = require('yuuko');
module.exports = new EventListener('ready', ({client}) => {
// client = bot
console.log(`Logged in as ${client.user.usename}`);
});
owo.js
.const { Command } = require('yuuko');
module.exports = new Command('owo', (message, args, context) => {
message.channel.createMessage('OwO');
});
meme
command in my following post. Stay tuned!│ .env
│ index.js
│ package-lock.json
│ package.json
│
├───commands
│ owo.js
│
├───events
│ ready.js
│
└───node_modules
│ ...