discord.js-games
TypeScript icon, indicating that this package has built-in type declarations

1.1.8 • Public • Published

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.

Package Sidebar

Install

npm i discord.js-games

Weekly Downloads

1

Version

1.1.8

License

MIT

Unpacked Size

59.6 kB

Total Files

36

Last publish

Collaborators

  • carelessinternet