An all in one discord bot made using the discord.js library. The bot works using slash commands, and as for non slash commands, the prefix is q.
The bot allows the server owner to choose which all command types should be enabled in that server
For any user in that server, in order to view which all are the allowed types, simply run the following command in the server:
q.allowed_commands
The output of this functions should be the following if, as an example, all the commands are turned on, except the chess commands:
Enabled commands:
- Admin
- Code
- Math
- Misc
- Random
- Science
- Time
Disabled commands:
- Chess
For the server owner to choose which all commands must be enabled or disable, the q.allow_command
command, which is case insensitive.
q.allow_command [TYPE] [BOOLEAN: true, false]
For example, to disable the chess command, the following command should be run in the server:
q.allow_command chess false
Or for example, to enable the math command, the following command should be run in the server:
q.allow_command math true
The command types would be the same as the name of the folder that holds those commands, which are present under the commands folder. The changes will all be saved into a json file (allowed_comamnds.json
), in the source folder, which must be present for the program to run.
These are commands reserved just for the creator of the bot, for debugging the bot, editting the console, getting some data from the bot, controlling the bot, etc.
The following are the syntax of all of these commands:
q.cls # Clears the console
q.deletemsg [message_id] # Deletes a message
q.echo [user | channel] [object_id] [content] # Sends a message
q.guild_ids # Collects the server IDs of all the servers the bot is in
q.guild_names # Collects the names of the servers the bot is in
q.readfile [path] # Outputs the contents of a path
q.readfolder [path] # Outputs the files and folders
q.status [online | dnd | idle | invisible] # Change the status of the bot
q.stop # Stops the bot
These can be gotten using the q.help command as well, whose output should contain the names of all the owner commands. Though it can provide a description for all the owner commands like this:
q.help [commands_name]
The output should something like this if the inputted command was the echo command for example
Description:
Send a message to a user or channel
Syntax:
q.echo ( user / channel ) id content
Commands are divided based on a type, these types are the following:
A help command is also present to provide all the commands in a specific type
/help [type]
The following few sections shall look over all the commands within these types
Admin commands are commands generally usable only by those given some higher permission in a server.
The commands given as admin commands are the following:
This command simply removes a member from the server, it does not permanently remove them.
Syntax
/kick [user]
As the name suggests, this command simply bans a user from the server. Once run, the user will be immediately banned from the server.
Syntax
/ban [user]
This command removes the ban on a user, basically re-allowing them to rejoin the server after having been banned. Note that this command needs you to input the user's id instead, which can be acquired from the server settings.
Syntax
/unban [user_id]
These are commands that allow using chess inside of discord itself.
The commands given as chess commands are the following:
This command returns all the possible moves in a given position
Syntax
/possible_moves [fen]
This commands generates a random game, full of just random moves, till the game is over
Syntax
/random_game
This commands checks whether a given fen is valid or not
Syntax
/validate_fen [fen]
This command allows you to play chess in discord itself. It seperated into the following subcommands:
/chess challenge [user]
/chess accept [user]
/chess move [opponent] [move]
/chess resign [opponent]
/chess position [user] [opponent]
/chess stats [user]
/chess get_game [user_id] [opponent_id] [index]
/chess total_games_against [user_id] [opponent_id]
/chess current_games
- Challenge: This subcommand allows you to challenge another user.
- Accept: This allows you to accept a challenge from another user.
- Move: Allows you to make a move in a current game. The move must be in algebraic notation.
- Resign: This allows you to resign a current game
- Position: This subcommand shows you the current position
- Stats: This shows you the total wins, losses, and draws made by a user
- Get game: Shows you a past game of a user against some other user
- Total games against: This gives you the total number of games a user has made against another
- Current games: This subcommand gives you all the total games being played currently
These are commands that are related to programming or files
The commands that come under the code type are the following:
This command allows you to display a snippet of code in a neat embed. Upon running the command, a prompt will come up asking for the file type and the code. The file type is required for the code highlighting. The code will then be displayed in clean embed in discord constisting of the author of the code at the top, and the code itself.
Syntax
/display_code
This command allows you to display a local file from your device in a neat embed.
Syntax
/display_file [file: Has to be attached] [description: Unrequired]
These commands were primarily the focus of the bot, so it makes sense that there is a lot of math commands in the bot. It should be commands that can allow you to use it like a calculator, and does some boring tasks for you.
The commands that come under the math type are the following:
- angle_radian_conversion
- antifactorial
- average
- change_base
- ci_amount
- constant
- cos
- sin
- tan
- differentiate_function
- integrate_function
- evaluate
- factorial
- factors
- fibonacci
- herons_formula
- hyperfactorial
- is_prime
- nth_prime
- natural_log
- pascals_triangle
- polynomial_from_outputs
- quadratic_equation
- solve_x
- sum_ap
- summation
- twonum
- use_formula
- saved_formulas
This function does the conversion from degrees to radians or vice versa.
Syntax
/angle_radian_conversion [value] [convert_to: Radians | Angles]
The inverse of the factorial function. Finds the number whose factorial is the given number.
Syntax
/antifactorial [number]
Computes the average from a set of inputs, i.e. numbers seperated by commas.
Syntax
/average [numbers]
Changes the base of the given number from base-10 to some other base.
/change_base [number: in base-10] [new_base]
Computes the amount of compound intrest acquired over some time. It can compute for yearly, half yearly, or quarter yearly.
Syntax
/ci_amount [type: Yearly | Half yearly | Quarter yearly] [principly] [rate] [time]
Gives the value of a given constant in math
Syntax
/constant [name: π | e | 𝜏 | γ | φ]
Computes the cosine of an angle in radians
Syntax
/cos [radians]
Computes the sin of an angle in radians
Syntax
/sin [radians]
Computes the tan of an angle in radians
Syntax
/tan [radians]
Finds the value of the derivative of a function at some value
Syntax
/differentiate_function [function] [at]
Finds the value of the definite integral of a function between two bounds
Syntax
/integrate_function [function] [from] [to]
Calculate the value of a given math expression. Note that the expression must be a valid expression, using only math numbers and symbols.
Syntax
/evaluate [expression]
Compute the factorial of a number. The number must a positive non-zero integer to work.
Syntax
/factorial [number]
Find the factors of a number, i.e. all the numbers that can be used to multiply with other numbers to get the original number back.
Syntax
/factors [number]
Find the nth number in the Fibonacci sequence, i.e. a sequence of numbers such that the next number is the sum of the previous two.
Syntax
/fibonacci [term]
A formula to calculate the area of a scalene triangle given the length of all its sides.
Syntax
/herons_formula [side_1] [side_2] [side_3]
The hyperfactorial of a number is the product of all the natural numbers from 1 to that number to the power of the current number
Syntax
/hyperfactorial [number]
Checks whether a given number is prime or not, i.e. a number divisible by only 1 and itself.
Syntax
/is_prime [number]
This command finds the nth prime number. It uses a large json file, which was created in python using a sufficiently fast algorithm, to get the first million prime numbers.
Syntax
/nth_prime [index]
Find the natural log of a number
Syntax
/natural_log [number]
Finds the value of Pascal's triangle at some row and column
Syntax
/pascals_trangle [row] [column]
Finds the polynomial satisfying the given outputs, if the outputs corrospond to x-values from 1 to some value
Syntax
/polynomial_from_outputs [outputs: Seperated by commas]
Compute the roots of a quadratic polynomial
Syntax
/quadratic_equation [a: The coefficient of x^2] [b: The coefficient of x] [c: The constant]
Find the roots of a function using Newton's method, given the initial value
Syntax
/solve_x [function] [equal_to] [x0]
Find the sum of an arithmetic progression
Syntax
/sum_ap [first_term] [number_of_terms] [common_difference]
Calculates the summation between two bounds of a function
Syntax
/summation [start] [stop] [function]
This command finds two numbers that satisfy a condition given an initial two numbers. The possible conditions are the following:
- Sum & Difference
- Product & Quotient
- Sum & Product
Syntax
/twonum [category: sum_difference | product_quotient | sum_product] [number1] [number2]
This command allows you to type out a formula, and then plug in the values you want, and then the program evaluates the result. All the values in the values
variable must be seperated using commas, and the assigned variable must be followed by an equals with the value you want to give it.
Syntax
/use_formula [formula] [values]
This is a command that allows you to save formulas, use them, and delete them. The formulas are saved in a json file holding your user id, thus the formulas are saved indirectly in your discord account. This command has sub commands (commands coming under it), the following are the syntax of each:
Syntax
/saved_formulas list
/saved_formulas read [name]
/saved_formulas use [name] [inputs]
/saved_formulas add
/saved_formulas delete [name]
- List: This one simply lists out the names of all the saved scripts
- Read: The read command allows you to read the saved script and variables of a given formula
- Use: This command allows you to use any one of your scripts. The name being the name of the saved formula, and the inputs all seperated by commas. The inputs can contain mathematical constants such as pi, e, phi, etc.
- Add: This commands allows the user to add and create a new command (or set a previously existing one). The command opens up a popup, where you can input in the name of the formula, all its variables (all must be single characters), and the script.
- Delete: This command allows you to delete a script permanently.
Script syntax
- Every line must begin with either
text:
oreqnt:
- If the line starts with
text:
, then it will simply display the text present there - If the line starts with
eqnt:
, the program will evaluate that line with the substituted variables - The eqnt lines must always only have numbers, variables, operators, and whitespaces.
- After each line, the program automatically goes to the next line. To prevent it, put
CONT
at the end of that line for it to continue to the next line. - If you want to display a variable in the text line with the inputted value, then you can state
VAR:[variable_name]
, and it will display the value of the inputted variable - Trigonometric functions such as sin, cos, and tan are supported
- If you want to add some characters in the text line not there in your keyboard, for example the pi symbol, the
CHAR:[name]
statement can be used for many common characters. Exponents can be expressed withCHAR:exp_[exponent]
, obviously to express power of multiple digit, you simply put them together. All the validCHAR
characters are the following:
CHAR:pi
CHAR:upper_pi
CHAR:tau
CHAR:phi
CHAR:gamma
CHAR:delta
CHAR:zeta
CHAR:sigma
CHAR:exp_0
CHAR:exp_1
CHAR:exp_2
CHAR:exp_3
CHAR:exp_4
CHAR:exp_5
CHAR:exp_6
CHAR:exp_7
CHAR:exp_8
CHAR:exp_9
Example: Here is an example of the simple script for the quadratic equation, with the name QuadraticEqnt
:
text:let **a** = VAR:a
text:let **b** = VAR:b
text:let **c** = VAR:c
text:axCHAR:exp_2 + bx + c = VAR:axCHAR:exp_2 + VAR:bx + VAR:c = 0 => x = CONT
eqnt: (-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a) CONT
text: or CONT
eqnt: (-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)
If you run the following command, where a=1, b=-3, and c=2:
/saved_formulas use name: QuadraticEqnt inputs: a=1,b=-3,c=2
The output should look like the following:
let a = 1
let b = 2
let c = 1
ax² + bx + c = 1x² + 2x + 1 = 0 => x = 1 or 2
These commands are ones that don't fall in some specific type, thus are under this more general type.
The commands that come under the misc type are the following:
This function applies the Ceaser cipher onto a string of text by some shift
Syntax
/caeser_cipher [text] [shift]
Simply does a coinflip
Syntax
/coinflip
Create a neat embed with a title, description, image, thumbnail, a footer, and a URL. The URL us present at the text that holds the name of the author present in the embed. None of the arguments to this command is required.
Syntax
/embed [title] [description] [image] [thumbnail] [footer] [url]
Play rock, paper, scissors against a random choice.
Syntax
/rps [choice: Rock | Paper | Scissor]
These commands involving choosing a random value. Note that no value returned is genuinely random, it is only pseudo-random, as computers are unable to generate genuinely random numbers.
The commands that come under the random type are the following:
Chooses a random number between two given values
Syntax
/randint [lower_bound] [upper_bound]
Chooses a random option from a set of objects
Syntax
/randoption [list: Seperated by commas]
These commands are more science related commands that generally works using chemistry and physics calculations
The comands that come under the science type are the following:
This function allows you to give one information of an element from the periodic table, such as the name, symbol, or atomic number, and it can return the other two values. The type
argument refers to the value you are inputting.
Syntax
/element [type: Name | Symbol | Atomic number] [input: Must corrospond to type]
This command returns the image of the periodic table
Syntax
/periodic_table
This command converts a word into a set of elements, whose symbols corrospond to that word when placed together. Note that if there are multiple solutions, this program with only give the first one it finds.
Syntax
/word_to_elements [word]
These are commands more related to the time, day of the week, month, etc.
The commands that come under the time type are the following:
This command returns that day of the week a specific date is. If the date is invalid, then the program will be unable to find the day it was.
Syntax
/day_of_week [day] [month] [year]
This command returns the number of days present in a given month.
Syntax
/days_for_month [month]
This command returns the current time it is, but in the coordinated universal time (utc).
Syntax
/utc
Some environment variables must be present for the program to run, with data that must be set by the owner. This file must be named .env
, and must by present just outside the source
folder. The following are the variables inside of the file:
- Token
- Client ID
- Owner ID
- Console channel ID
Email address: farismuhd172009@gmail.com