discord.js-games

A Discord.js v13 module for minigames

Usage no npm install needed!

<script type="module">
  import discordJsGames from 'https://cdn.skypack.dev/discord.js-games';
</script>

README

discord.js-games

A discord.js v13 module which allows you to add minigames to your bot super easily!

Notable Features

  • Slash commands and messages support
  • Gives result of the game back
  • Promise-based
  • Customisable
  • Easy to implement
  • TypeScript support

Documentation

You can find it in the wiki section of the GitHub repository.

How to??????

Installation

npm i discord.js-games

Playing

CommonJS Example

const { GuildMember } = require('discord.js');
const { blackjack, rps } = require('discord.js-games');

client.on('interactionCreate', async interaction => {
  if (!interaction.isCommand()) return;
  
  if (interaction.commandName === 'blackjack') {
    const result = await blackjack({ message: interaction });

    console.log('user won', result);
  } else if (interaction.commandName === 'rps') {
    rps({ message: interaction });
  }
});
client.on('messageCreate', async message => {
  if (message.content === 'blackjack') {
    blackjack({ message });
  } else if (message.content === 'rps') {
    const opponent = message.mentions.members?.first();
    const result = await rps({
      message,
      ...(opponent instanceof GuildMember && { opponent })
    });

    console.log('user won', result);
  }
});

ES6/TypeScript Example

import { GuildMember } from 'discord.js';
import { blackjack, rps } from 'discord.js-games';

client.on('interactionCreate', async interaction => {
  if (!interaction.isCommand()) return;
  
  if (interaction.commandName === 'blackjack') {
    const result = await blackjack({ message: interaction });

    console.log('user won', result);
  } else if (interaction.commandName === 'rps') {
    rps({ message: interaction });
  }
});
client.on('messageCreate', async message => {
  if (message.content === 'blackjack') {
    blackjack({ message });
  } else if (message.content === 'rps') {
    const opponent = message.mentions.members?.first();
    const result = await rps({
      message,
      ...(opponent instanceof GuildMember && { opponent })
    });

    console.log('user won', result);
  }
});

Issues, bugs, questions, PRs, etc

Open up an issue for anything relating to this package, that can be bugs, issues, feature requests, etc. Same goes for pull requests, feel free to submit one for improved performance, better code practices, etc.