Skip to content
nutmeg edited this page Jan 30, 2023 · 32 revisions

Discord.PS Documentation

Setting Up

== Discord.JS Client ==

Discord.PS is built off of Discord.JS so for it to work you need Discord.JS.

const { Client } = require('discord.js');
const discordClient = new Client({
	// your stuff here
});

== Discord.PS Client ==

once you have your Discord.JS client you can add in Discord.PS.
(prefix is optional)

const { PSClient } = require('discord.ps');
const client = new PSClient({
	client: discordClient,
	prefix: "!" 
});

once you have your ps client set up and working you can run it using this:

client.login(token);

Events

Discord.PS is a combination of Discord.JS and Discord.PY so both work for the most part.

// Discord.JS
client.on("ready", (ctx) => {
	console.log(`Logged in as ${ctx.user.tag}.`);
});
// Discord.PS
client.event("ready", (ctx) => {
	console.log(`Logged in as ${ctx.user.tag}.`);
});

Discord.PS expands mostly on event names as there are a lot more names for events

for a full list of all event names either go to here or do this:

console.log(client.eventList);

Commands

same as events all Discord.JS commands will still function the same even if you use things from Discord.PS client

// Discord.JS
client.on("messageCreate", async (ctx) => {
	if (!ctx.content.startsWith(prefix) || ctx.content.endsWith(prefix) && ctx.content.startsWith(prefix)) return;
	
	if (ctx.content == `${prefix}test`) {
		console.log(ctx.content);
	}
});

however, Discord.PS has an entirely different command system that's similar to Discord.PY
keep in mind that command names, aliases, and prefixes are automatically made to be lowercase so do not use capital letters.

// Discord.PS
client.command( {name: "test"}, async (ctx) => {
	console.log(ctx.content);
});

== Args N Stuffs ==

Command Info:

  • name: the name of the command String
  • aliases: secondary names for the command Array
  • cooldown: how long until a user can run a command again (uses seconds) Number

Command Function:

  • ctx: command context (ctx.content)
  • cmd: command info (cmd.name, cmd.args, cmd.cooldown)

Command Info (CMD):

  • cmd.name: name of the command String
  • cmd.args: array of the command's arguments Array
  • cmd.onCooldown: if the command is on cooldown Boolean
  • cmd.cooldownType: type of cooldown (command or global) String
  • cmd.cooldown: cooldown info Object
// message: !test a b c
client.command( {name: "test", aliases: ["testcommand", "commandtest"], cooldown: 5 }, async (ctx, cmd) => {
	console.log(ctx.content); // "!test a b c"
	console.log(cmd.name); // "test"
	console.log(cmd.args); // ["a", "b", "c"]
	console.log(cmd.onCooldown); // false
	console.log(cmd.cooldownType); // null
	console.log(cmd.cooldown); // null
});

== Cooldown Handling ==

unfortunately due to JavaScript limitations I wasn't really able to add a real countdown until when the cooldown is up

client.command( {name: "test", cooldown: 5 }, async (ctx, cmd) => {
	if (cmd.onCooldown) {
		return client.reply("command is on cooldown!");
	}
});

if you want a full list of the bot's commands you can do this:

console.log(client.commandList);

Ugly Documentation

Client.login() : None

login with a token
takes a token as a string

client.login(token);

Client.command() Object

creates a new command

client.command( {name: "name", alises: ["aliases"], cooldown: 5}, async (ctx, cmd) => {
	// do stuff
});

Client.fetchCommand() Object

to fetch a command you can use this
takes a command name and a function (optional)

let command = client.fetchCommand("test");
console.log(command.name);

or

client.fetchCommand("test", (command) => {
	console.log(command.name);
});

Client.commandExists() Boolean

to check if a command exists you can use this
takes a command name

let exists = client.commandExists("test");

Client.executeCommand() Function

mostly used for parts of the api but you can use it if you want
used to execute commands with script instead of with messages

client.executeCommand(name, ctx, cmd);

Client.commandFormat() Object

to format a command you can use this
takes a string

// message: "!test a b c"
let format = client.commandFormat(message);
console.log(format.name); // "test"
console.log(format.args); // ["a", "b", "c"]

Client.commandHandler() None

mostly used for parts of the api but you can use it if you want
used to handle commands from messages

discordClient.on("messageCreate", async (ctx) => {
	Holder = [client, discordClient, ctx];
	client.commandHandler(ctx);
});

Client.commandList Array

returns an array of all the commands for the bot

console.log(client.commandList);

Client.eventList Object

returns an array of all the events

console.log(client.eventList);

Client.event() Function

does something when an event happens

client.event("join", async (ctx) => {
	console.log("user joined!");
});

Client.colors Object

for a full list of colors you can either go to here or do this:

console.log(client.colors);
let embed = client.Embed({
	description: "a",
	color: client.colors.blurple
});

Client.colorFormat() Number

converts a hex color into an 0x int color for use in embeds

client.colorFormat(client.colors.blurple); // 0x7289da

Client.Embed() Object

edited version of the normal message embeds for more simplicity
for all of the ones that have url removed you can still use it especially for things like footer

let embed = client.Embed({
	name: "name",
	description: "description",
	color: client.colors.blurple,
	
	image: "url",
	thumbnail: "url",
	
	// the normal {url: "url"} for image and thumbnail still work if you want to use them
	
	fields: [
		{name: "test", value: "a b c", inline: true},
		{name: "test2", value: "d e f", inline: false}
	],
	
	footer: "a"
	
	// footer: {name: "a"}
	// footer: {text: "a", icon: "url"}
	// footer: {text: "a", iconURL: "url"}
	
	timestamp: client.time.now.embed
});

client.channel.send({embeds: [embed]});

Client.Button Object

edited version of the normal message buttons for way more simplicity
for more info on buttons and button styles go here

let button = client.Button({
	id: "id",
	label: "label",
	emoji: "emoji", // even tho pretty sure emoji and label can't be in the same button but eh
	style: "primary"
});

Client.buttonStyle() Number

takes a string and converts it into the cooresponding number

console.log(client.buttonStyle("primary")); // 1

Client.Selection() Object

edited version of the normal message select menus for way more simplicity
for more info on select menus go here

let select = client.Selection({
	id: "id",
	label: "label",
	min: 1,
	max: 4,
	options: [
		{ label: "A", value: "A", description: "Option A" },
		{ label: "B", value: "B", description: "Option B" },
		{ label: "C", value: "C", description: "Option C" },
		{ label: "D", value: "D", description: "Option D" },
	]
});

Client.ActionRow() Object

takes an array and returns a new action row
used for buttons and stuff

let button1 = client.Button({ /* button stuff */});
let button2 = client.Button({ /* button stuff */});

let row = client.ActionRow([button1, button2]);

client.channel.send({ components: [row] });

Client.fetchUser() User

takes an id or @mention and gets user info from the bot's user cache

let user = client.fetchUser("id");

console.log(user.tag);

Client.fetchGuildUser() User

takes an id or @mention and gets user info from a guild's users

let user = client.fetchGuildUser("id");

console.log(user.tag);

Client.fetchChannel() Channel

takes an id or #channel mention and gets channel info from the bot's channel cache

let channel = client.fetchChannel("id");

console.log(channel.name);

Client.fetchGuildChannel() Channel

takes an id or #channel mention and gets channel info from a guild's channels

let channel = client.fetchGuildChannel("id");

console.log(channel.name);

Client.fetchGuildRole() Role

takes an id or @role mention and gets role info from a guild's roles

let role = client.fetchGuildRole("id");

console.log(role.name);

Client.time String

outputs a string with a timestamp that can be used by discord for more info on how timestamps work go here

let embed = client.Embed({
	description: "a",
	timestamp: client.time.now.embed
});

client.channel.send(client.time.now.relative, {embeds: [embed]});
Types:
  • Set: takes a given time and turns it into a usable time for discord (ex: client.time.set.default("28 November 2018 09:01"))
  • Now: uses the current time and turns it into a usable time for discord (ex: client.time.set.relative)
Times:
  • embed: time for embeds
  • default: default time
  • shortTime: shorter version of the time
  • longTime: longer version of the time
  • shortDate: shorter version of the date
  • longDate: longer version of the date
  • shortDT: shorter version of the date and time
  • longDT: longer version of the date and time
  • relative: time relative to the current time

Client.channel.send() CTX

sends a message to a channel
takes message content and an extras object

let message = await client.channel.send("abc", {embeds: [embed], components: [row]});

Client.reply() CTX

replies to a message
takes message content and an extras object

let message = await client.reply("abc", {embeds: [embed], components: [row]});

Client.channel.purge() None

purges a channel for a given amount of messages
channel is optional and defaults to the ctx channel if not given

client.channel.purge(5, channel);

Client.channel.lock() None

locks a channel making it so the @everyone role can't speak
channel is optional and defaults to the ctx channel if not given

client.channel.lock(channel);

Client.channel.unlock() None

unlocks a channel making it so the @everyone role can speak again
channel is optional and defaults to the ctx channel if not given

client.channel.unlock(channel);

Client.voice.lock() None

mutes and deafens everyone in a voice channel
takes a channel

client.voice.lock(channel)

Client.voice.unlock() None

unmutes and undeafens everyone in a voice channel
takes a channel

client.voice.unlock(channel)

Client.voice.join(channel) None

makes the bot join a voice channel
takes a channel

client.voice.join(channel)

Client.voice.leave(channel) None

makes the bot leave a voice channel
takes a channel

client.voice.leave(channel)

Client.guild.memberCount Number

returns the amount of members a guild has

client.guild.memberCount

Client.guild.roleCount Number

returns the amount of roles a guild has

client.guild.roleCount

Client.guild.channelCount Number

returns the amount of channels a guild has

client.guild.channelCount

Client.guild.emojiCount Number

returns the amount of emojis a guild has

client.guild.emojisCount

Client.guild.stickerCount Number

returns the amount of stickers a guild has

client.guild.stickerCount

Client.guild.members() Function

lets you get every member in a server

client.guild.members( (members) => {
	members.forEach( (member) => {
		// do stuff
	});
});

Client.guild.roles() Function

lets you get every role in a server

client.guild.roles( (roles) => {
	roles.forEach( (role) => {
		// do stuff
	});
});

Client.guild.channels() Function

lets you get every channel in a server

client.guild.channels( (channels) => {
	channels.forEach( (channel) => {
		// do stuff
	});
});

Client.guild.emojis() Function

lets you get every emoji in a server

client.guild.emojis( (emojis) => {
	emojis.forEach( (emoji) => {
		// do stuff
	});
});

Client.guild.stickers() Function

lets you get every sticker in a server

client.guild.stickers( (stickers) => {
	stickers.forEach( (sticker) => {
		// do stuff
	});
});
Clone this wiki locally