This package has been deprecated

Author message:

This package will no longer be maintained, see https://github.com/biologyscience/discord-games-beta/blob/main/deprecated.md for more info

discord-games-beta

2.8.0 • Public • Published

This package will no longer be maintained, see https://github.com/biologyscience/discord-games-beta/blob/main/deprecated.md for more info

Discord Games BETA

NOTE:

This is my first npm package, used for testing with my friends. Feel free to continue reading if you want to use it for yourself.


If you have any errors or issues, please update the package by doing npm i discord-games-beta and read the contents in the usage section to make sure you have coded it correctly
If that doesn't solve your error, have a look at the Known Issues section.

What is this ?

This is a package used to enable an game event inside a Discord Voice Channel, like YouTube Watch Togther, Chess, Word Tile, and much more.

How does this work ?

This works by creating an invite to a voice channel of your will in such a way that is makes game playable in that specific voice channel.

Installation

npm i discord-games-beta

Usage

  • Constructor:
const DiscordGame = require('discord-games-beta');
const game = new DiscordGame(params);
  • Params:
/**
 * (YourDiscordBotToken, NameOfTheGame, MaximumDuration, {Options})
 */

const game = new DiscordGame('Token', 'chess', 2, {neverExpire: false});

/**
 * "Token" is the Discord Client which you are using in your code
 * "chess" is the name of the game which you wanted to play
 * "2" is the Maximum Duration of the game event in hours
 * 
 * "neverExpire" is an optional parameter by which you can choose wheater you want your invite link to get expired or not
 * Normally it will get expired after the "MaximumDuration" but by setting the parameter to true, the link will not expire on its own
 */

NOTE: The Maximum Duration can only be more than 0


  • Function:
game.play(vc).then(result => console.log(result));

// "vc" is the Discord Voice channel which you want to play the game in.
  • Result:
{
    code : String // Code of the invite link
    inviteLink : String // The invite link itself
    createdAt : Date // The time when the invite was created
    validTill : Date | String // The time at which the invite gets expired, if 'neverExpire' is set as 'true' you will get a string

    guild :
    {
        ID : String // ID of the server in which the invite has been made
        name : String // Name of the server in which the invite has been made
    },

    channel :
    {
        ID : String // ID of the channel to which the invite has been made
        name : String // Name of the channel to which the invite has been made
    },

    inviter : 
    {
        ID : String // ID of the user who made the invite (i.e, The Bot's ID which has been used to do the task)
        name : String // Name of the user who made the invite (i.e, The Bot's Name which has been used to do the task)
    },

    app :
    {
        ID : String // ID of the game
        name : String // Name of the game
        description : String // A short description of the game
        summary : String // A summary of the game
        maxMembers : String // Maximum number of members the game allows
    }
}

Example Code (for one game)

const Discord = require('discord.js');
const DiscordGame = require('discord-games-beta');

const client = new Discord.Client();
const YouTube = new DiscordGame('Token', 'youtube', 2);

client.on('messageCreate', (message) =>
{
    if (message.content === 'play')
    {    
        const VoiceChannel = message.member.voice.channel;  // The voice channel in which the event is gonna occur

        YouTube.play(VoiceChannel).then(result => message.channel.send(result.inviteLink));
    }
});

client.login('Token');

Example Code (for one game)

What should I do if I want to play other games ?

Just replace name of the game which is the second parameter of constructor (i.e, new DiscordGame()) with any of the available games

To get the list of the available games you can do

const DiscordGame = require('discord-games-beta');
const game = new DiscordGame();

console.log(game.gameNames()); // This will print all the available games in your console !

Output:

youtube
poker
betrayal
fishing
chess
letterLeague
wordSnack
awkword
doodleCrew
spellCast
checkers
sketchHeads
blazing8s
landIO
puttParty
bobbleLeague
askAway
kwim    // Game name for "Know What I Meme"

Example code (for more than one games)

const Discord = require('discord.js');
const DiscordGame = require('discord-games-beta');

const client = new Discord.Client();

const YouTube = new DiscordGame('Token', 'youtube', 10);
const Chess = new DiscordGame('Token', 'chess', 1);
const LetterTile = new DiscordGame('Token', 'lettertile', 5);
const WordSnack = new DiscordGame('Token', 'wordsnack', 3);
const DoodleCrew = new DiscordGame('Token', 'doodlecrew', 2);

client.on('messageCreate', (message) =>
{
    if (message.content === 'play')
    {
        const games =
        [
            "🇦 - YouTube Watch Together",
            "🇧 - Chess",
            "🇨 - Letter Tile",
            "🇩 - Word Snack",
            "🇪 - Doodle Crew"
        ];

        const ReactionEmbed = new Discord.MessageEmbed()
        .setColor('#2F3136')
        .setDescription(`React to the appropriate emoji to start a game !\n\n${games.join('\n')}`);

        message.channel.send({embeds: [ReactionEmbed]}).then((msg) =>
        {
            msg.react('🇦');
            msg.react('🇧');
            msg.react('🇨');
            msg.react('🇩');
            msg.react('🇪');

            const collector = new Discord.ReactionCollector(msg);
    
            collector.on('collect', (reaction) =>
            {
                collector.stop();

                const VoiceChannel = message.member.voice.channel;  // The voice channel in which the event is gonna occur

                const data =
                {
                    "🇦" : YouTube,
                    "🇧" : Chess,
                    "🇨" : LetterTile,
                    "🇩" : WordSnack,
                    "🇪" : DoodleCrew
                };

                data[reaction.emoji.name].play(VoiceChannel).then((result) => message.channel.send(result.inviteLink));
            });
        });
    }
});

client.login('Token');

Example code (for more than one games)


Known Issue:

Most common error. Caused due to version mismatch of node-fetch

Error:

\node_modules\discord-games-beta\index.js:1
const fetch = require('node-fetch');
              ^

Error [ERR_REQUIRE_ESM]: require() of ES Module ... 

Fix:

  • Open up your terminal
  • Do npm rm node-fecth
  • Then do npm i node-fetch@2.x

If you face any other issue, feel free to create an issue on the issues page in the github repository

Have Fun 🥳


F.A.Q:

Do you work for Discord ?

No, I do not work for or related to Discord in any means, I am just a normal person who uses it.

Did you make this package ?

Yes, I am only person who made this package.

Did you make these games ?

No, I did not make these games. All these games were made by a group of people in Discord Games Lab.

Do not expect frequent changes to this package (unless there is a new game release or changes in a game) as this package is only used to test with my friends, but it works fine with everyone.
If you have any questions, you may add me in Discord: BIOLOGY SCIENCE#1756

Package Sidebar

Install

npm i discord-games-beta

Weekly Downloads

5

Version

2.8.0

License

ISC

Unpacked Size

17.6 kB

Total Files

4

Last publish

Collaborators

  • biologyscience