Discord Js Slot Machine



The discord API provides you with an easy tool to create and use your own bots and tools.

  1. Discord Js Kick Command
  2. Discord Js Github
  3. Discord Js Slot Machine Jackpots
  4. Discord Js Documentation
  5. Discord Js Slot Machine Bot

Slot machine Sound Effects (194) Most recent Oldest Shortest duration Longest duration Any Length 2 sec 2 sec - 5 sec 5 sec - 20 sec 20 sec - 1 min 1 min All libraries Radio Mall SFX Bible BLASTWAVE FX Frank Serafine John Leonard Richard Humphries WW Audio Epic Stock Media Fusehive Ryan Wassil 2496 Sound Effects. NPM Dependencies: express, discord.js, node-fetch, @discordjs/opus (far less dependencies than pre-2.0) Simple to use No permissions to set up if you don't want to. Primarily a casino discord bot, with evolving customizability, tons of casino games, and modernized features rewritten from the old. Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time. I have been coding my Discord bot using Discord.JS for about 2 months now and I've just recently noticed that my bot isn't saying that it's playing what I'm telling it. When I first coded the bot up.

Today we are going to take a look at how we can create a basic music bot and add it to our server. The bot will be able to play, skip, and stop the music and will also support queuing functionality.

Prerequisites

Before we get started creating the bot make sure that you have installed all the needed tools.

After the installation, we can continue by setting up our discord bot.

Setting up a discord bot

First, we need to create a new application on the discord development portal.

We can do so by visiting the portal and clicking on new application.

After that, we need to give our application a name and click the create button.

After that, we need to select the bot tab and click on add bot.

Now our bot is created and we can continue with inviting it to our server.

Adding the bot to your server

After creating our bot we can invite it using the OAuth2 URL Generator.

For that, we need to navigate to the OAuth2 page and select bot in the scope tap.

After that, we need to select the needed permissions to play music and read messages.

Then we can copy our generated URL and paste it into our browser.

After pasting it, we add it to our server by selecting the server and clicking the authorize button.

Creating our project

Now we can start creating our project using our terminal.

First, we create a directory and move into it. We can do so by using these two commands.

After that, we can create our project modules using the npm init command. After entering the command you will be asked some questions just answer them and continue.

Then we just need to create the two files we will work in.

Now we just need to open our project in our text editor. I personally use VS Code and can open it with the following command.

Discord js basics

Now we just need to install some dependencies before we can get started.

After the installation finished we can continue with writing our config.json file. Here we save the token of our bot and the prefix he should listen for.

To get your token you need to visit the discord developer portal again and copy it from the bot section.

That are the only things we need to do in our config.json file. So let’s start writing our javascript code.

First, we need to import all our dependencies.

After that, we can create our client and login using our token.

Now let’s add some basic listeners that console.log when they get executed.

After that, we can start our bot using the node command and he should be online on discord and print “Ready!” in the console.

Reading messages

Now that our bot is on our server and able to go online, we can start reading chat messages and responding to them.

Discord js github

To read messages we only need to write one simple function.

Here we create a listener for the message event and get the message and save it into a message object if it is triggered.

Now we need to check if the message is from our own bot and ignore it if it is.

In this line, we check if the author of the message is our bot and return if it is.

After that, we check if the message starts with the prefix we defined earlier and return if it doesn’t.

After that, we can check which command we need to execute. We can do so using some simple if statements.

In this code block, we check which command to execute and call the command. If the input command isn’t valid we write an error message into the chat using the send() function.

Now that we know which command we need to execute we can start implementing these commands.

Adding songs

Let's start by adding the play command. For that, we need a song and a guild (A guild represent an isolated collection of users and channels and is often referred to as a server). We also need the ytdl library we installed earlier.

First, we need to create a map with the name of the queue where we save all the songs we type in the chat.

After that, we create an async function called execute and check if the user is in a voice chat and if the bot has the right permission. If not we write an error message and return.

Now we can continue with getting the song info and saving it into a song object. For that, we use our ytdl library which gets the song information from the youtube link.

This will get the information of the song using the ytdl library we installed earlier. Then we save the information we need into a song object.

After saving the song info we just need to create a contract we can add to our queue. To do so we first need to check if our serverQueue is already defined which means that music is already playing. If so we just need to add the song to our existing serverQueue and send a success message. If not we need to create it and try to join the voice channel and start playing music.

Here we check if the serverQueue is empty and add the song to it if it’s not. Now we just need to create our contract if the serverQueue is null.

In this code block, we create a contract and add our song to the songs array. After that, we try to join the voice chat of the user and call our play() function we will implement after that.

Playing songs

Discord Js Slot Machine

Now that we can add our songs to our queue and create a contract if there isn’t one yet we can start implementing our play functionality.

First, we will create a function called play which takes two parameters (the guild and the song we want to play) and checks if the song is empty. If so we will just leave the voice channel and delete the queue.

After that, we will start playing our song using the play() function of the connection and passing the URL of our song.

Here we create a stream and pass it the URL of our song. We also add two listeners that handle the end and error event.

Note: This is a recursive function which means that it calls itself over and over again. We use recursion so it plays the next song when the song is finished.

Discord Js Kick Command

Now we are ready to play a song by just typing !play URL in the chat.

Skipping songs

Now we can start implementing the skipping functionality. For that, we just need to end the dispatcher we created in our play() function so it starts the next song.

Here we check if the user that typed the command is in a voice channel and if there is a song to skip.

Stoping songs

The stop() function is almost the same as the skip() except that we clear the songs array which will make our bot delete the queue and leave the voice chat.

Complete source code for the index.js:

Here you can get the complete source code for our music bot:

Conclusion

You made it all the way until the end! Hope that this article helped you understand the Discord API and how you can use it to create a simple bot. If you want to see an example of a more advanced discord bot you can visit my Github repository.

Discord js setup

If you have found this useful, please consider recommending and sharing it with other fellow developers.

If you have any questions or feedback, let me know in the comments down below.

About This File

Discord

Songbird's Repo
NPC, Scripts, Maps, Sprites, Mobs & More

Players love Slot Machines! Specially if it is easy to use with a pretty cutin-based interface!

This is a configurable Slot Machine where you're able to change the Item ID allowing you to use a custom or existing item, like Apples or a Casino exclusive coin bought with Zeny, this NPC allows you to configure the Odds, Payoff, and Winnings so you will always win! It is user-friendly and has a realistic cutin-based animation (575 .bmp files where used to create this).

WARNING: Bad use of this NPC can break your server's economy, if you don't know about Slot Machine formulas and odds, just configure the item ID '.CoinID' and '$SlotCoinPrice' variables.

NPC INFORMATION:

Discord Js Github

Slot Machine - This script is going to create 8 NPCs in the Comodo Casino, it is recommended to replace the cmd_in02 map with the provided one if you plan to use this location.

  • This Slot Machine has 5 images, here is the order from best to worse: Chest Coin, Bell, Yggdrasil, and Apple.
  • Configuration is script-based.
  • Prize is X times the bet (Depending on the multiplier) if the GiveItems feature is disabled.

Features for GMs:

  • You can configure the Odds, Winnings, and Payoff (An excel document is provided to help you configure this).
  • GM Menu where you can see/erase statistics (Password protected), batch play-test to calculate winning chance or play normally (this doesn't affect common player statistics).
  • General Player statistics (Gives you information about how many games have been lost, how much Zeny has been spent and the quantity of items earned by the users. (You can set Credit - Zeny price relation to calculate this: Default = 0).
  • 2 Prize options:
    • Credit Mode: Give credits like normal Slot Machines, you get X times the bet for combinations.
    • GiveItem Mode: Instead of earning credits, users will earn Items. This option disables the option to bet more than 1 coin per game.
  • Play Test Mode: You can batch-play X number of games to see quick statistics.

Features for Players:

  • Clean interface and easy to use (cutin-based animation).
  • Users can configure the spin speed so they can play faster.
  • Users can bet X1, X2, or x3 times in a single play. If they play x3 the Jackpot (3 Chests) pays extra (This is configurable too).
  • NPC Information (provided to the players) is updated automatically based in your configuration like winnings and prizes.
  • Sound feedback and effects!

WINNING COMBINATIONS (AND DEFAULT PRIZES):

  • x125
  • x40
  • x15
  • x6
  • x3
  • A A x2
  • A B x1

Where A and B can be any object.

WHAT CAN I DO WITH THIS NPC?

You can use it in a lot of ways! Here are some examples:

Discord Js Slot Machine Jackpots

  • To get event coins/tickets to be exchanged for other prices.
  • Zeny sink.
  • Poring Coins.
  • Cash Shop Pints (Custom item needed).
  • Costume Hat Ticket exchange.
  • Give coins so players can change them for items in this NPC, let luck decide.
  • And more!

FILE CONTENTS: (167 MB - 3 .rar files)

  • 1 Excel document to help you decide your winnings and payoff.
  • 1 Script
  • 1 Map (Replace cmd_in02 with this one if you plan to use this NPC here)
  • 6 .wav files (Sound effects)
  • 576 .bmp files (Cutins)
  • 1 sprite (A silver-colored version of the original Slot Machine NPC to match cutin)

BUYING TERMS:

  • You are not allowed to redistribute this script in any way, shape, or form.
  • Chargeback scams are not tolerated and will get you punished on rAthena.
  • I still retain all rights to this script.
  • You can modify this script as you like, but to receive support you must tell me what you changed.
  • No Renewal, free updates.

Contact Me on Discord: Songbird#3918

What's New in Version 1.8See changelog

Released

Discord Js Documentation

Now you can tell the Script to give Items instead of Credits with the Slot combinations.
Enabling this option disables the possibility to play with more than 1 coin.

Discord Js Slot Machine Bot

Statistics and Test-playing change accordingly if you set the script to give Items or Credits, telling you the number of items that players earn globally.