@abdevs/discord.js-utils 中文文档教程

发布于 3年前 浏览 26 项目主页 更新于 3年前

Discord.js Utils (Re-Coded in TypeScript)

banner

discord.js 库的实用程序包。 这包含 utils 函数和类,可轻松使用 Discord.js

Support

加入我们的 Discord Server 以获取任何与支持相关的查询。

Installation

npm i @abdevs/discord.js-utilsyarn add @abdevs/discord.js-utils

初始化

const discordUtils = require('@abdevs/discord.js-utils');
const { Client } = require('discord.js');
const client = new Client();
discordUtils.init(client, {
  isCmdManager: true,
  isHelpCommand: true,
  cmdManagerOptions: { prefix, isPrefixMap: false },
});
client.login(token);

Options

OptionDefaultDescription
isCmdManagerfalseEnables command manager
isHelpCommandfalseAdds a help command
cmdManagerOptions{ isPrefixMap: false, prefix: '!'}Command Manager Options

Features

Function / ClassDescription
MessageQuestionBuilds message question object
ReactionQuestionBuilds reaction question object
QuestionsAPIBuild the questions API. Lets you easily ask long sets of questions from single or multiple users.
askReactionQuestionLets your ask a single reaction question
askMessageQuestionLets your ask a single message question
ReactionMenuBuilds a reaction menu (Credits: Juby210)
PaginationMenuBuilds a pagination menu (Credits: Thomas Jowsey)
errorHandlerOne liner error handler
deepCloneWithLoseDeep clones a non-complex object
isValidSnowflakeIf the provide string is a valid snowflake
fetchUserFetches a user
fetchChannelFetches a channel
fetchGuildFetches a guild
fetchMemberFetches a member
fetchRoleFetches a role
toTimestampConverts string time eg: 5h2m into milliseconds
toTimeLeftConverts milliseconds to 1 Minute 20 Seconds format
getRandomIntA random number between the provided range
findCodeBlockFinds the groups between a string code block
findEmoteByIdFinds a emote by id
isValidEmailChecks if an email address is valid
getConfigCreates a config file or yml or json and returns the config object
SpamHandlerChecks if a user is spamming
getPrefixGets the default prefix or guild prefix
getPrefixMapGets the guild prefix map
registerCategoryRegisters a category
addCommandAdds a command
addMiddlewareAdds a middleware

Examples

QuestionsAPI Example

const {
  addCommand,
  MessageQuestion,
  ReactionQuestion,
  QuestionsAPI,
} = require('@abdevs/discord.js-utils');
const { MessageEmbed } = require('discord.js');

module.exports = async () => {
  addCommand({
    command: 'helpme',
    handler: async (message) => {
      const typeEmbed = new MessageEmbed({
        description: `What type of help you want?
            ❤: *Love Life*
            ????: *Money*`,
        color: 'RANDOM',
      });
      const moreInfo = new MessageEmbed({
        description: 'We need additional about your situation',
        color: 'RANDOM',
      });
      const api = new QuestionsAPI();
      const typeQuestion = new ReactionQuestion(message.author.id)
        .setQuestion({ embed: typeEmbed, reply: message.author })
        .setPossibleAnswers(['❤', '????'])
        .setRun(({ reaction }) => {
          if (reaction.emoji.name === '❤') return 'Love';
          return 'Money';
        });
      const helpQuestion = new MessageQuestion(message.author.id)
        .setQuestion({ embed: moreInfo, reply: message.author })
        .setRun(({ message }) => message.content);
      api.addQuestion([typeQuestion, helpQuestion]);
      const { data } = await api.ask(message.channel);
      const type = data[0].result;
      const info = data[1].result;
      const embed = new MessageEmbed({
        description: `${message.author.toString()} needs help with **${type}**
            *Here is some additional information:*
            ${info}`,
      });
      message.channel.send({ embed });
    },
  });
};

Terms and Conditions

此存储库仅供代码查找和个人使用。

您不得从该存储库中窃取代码。

Discord.js Utils (Re-Coded in TypeScript)

banner

A utils package for discord.js lib. This contains utils function and classes to easily work with Discord.js

Support

Join our Discord Server for any support related queries.

Installation

npm i @abdevs/discord.js-utils or yarn add @abdevs/discord.js-utils

Initialization

const discordUtils = require('@abdevs/discord.js-utils');
const { Client } = require('discord.js');
const client = new Client();
discordUtils.init(client, {
  isCmdManager: true,
  isHelpCommand: true,
  cmdManagerOptions: { prefix, isPrefixMap: false },
});
client.login(token);

Options

OptionDefaultDescription
isCmdManagerfalseEnables command manager
isHelpCommandfalseAdds a help command
cmdManagerOptions{ isPrefixMap: false, prefix: '!'}Command Manager Options

Features

Function / ClassDescription
MessageQuestionBuilds message question object
ReactionQuestionBuilds reaction question object
QuestionsAPIBuild the questions API. Lets you easily ask long sets of questions from single or multiple users.
askReactionQuestionLets your ask a single reaction question
askMessageQuestionLets your ask a single message question
ReactionMenuBuilds a reaction menu (Credits: Juby210)
PaginationMenuBuilds a pagination menu (Credits: Thomas Jowsey)
errorHandlerOne liner error handler
deepCloneWithLoseDeep clones a non-complex object
isValidSnowflakeIf the provide string is a valid snowflake
fetchUserFetches a user
fetchChannelFetches a channel
fetchGuildFetches a guild
fetchMemberFetches a member
fetchRoleFetches a role
toTimestampConverts string time eg: 5h2m into milliseconds
toTimeLeftConverts milliseconds to 1 Minute 20 Seconds format
getRandomIntA random number between the provided range
findCodeBlockFinds the groups between a string code block
findEmoteByIdFinds a emote by id
isValidEmailChecks if an email address is valid
getConfigCreates a config file or yml or json and returns the config object
SpamHandlerChecks if a user is spamming
getPrefixGets the default prefix or guild prefix
getPrefixMapGets the guild prefix map
registerCategoryRegisters a category
addCommandAdds a command
addMiddlewareAdds a middleware

Examples

QuestionsAPI Example

const {
  addCommand,
  MessageQuestion,
  ReactionQuestion,
  QuestionsAPI,
} = require('@abdevs/discord.js-utils');
const { MessageEmbed } = require('discord.js');

module.exports = async () => {
  addCommand({
    command: 'helpme',
    handler: async (message) => {
      const typeEmbed = new MessageEmbed({
        description: `What type of help you want?
            ❤: *Love Life*
            ????: *Money*`,
        color: 'RANDOM',
      });
      const moreInfo = new MessageEmbed({
        description: 'We need additional about your situation',
        color: 'RANDOM',
      });
      const api = new QuestionsAPI();
      const typeQuestion = new ReactionQuestion(message.author.id)
        .setQuestion({ embed: typeEmbed, reply: message.author })
        .setPossibleAnswers(['❤', '????'])
        .setRun(({ reaction }) => {
          if (reaction.emoji.name === '❤') return 'Love';
          return 'Money';
        });
      const helpQuestion = new MessageQuestion(message.author.id)
        .setQuestion({ embed: moreInfo, reply: message.author })
        .setRun(({ message }) => message.content);
      api.addQuestion([typeQuestion, helpQuestion]);
      const { data } = await api.ask(message.channel);
      const type = data[0].result;
      const info = data[1].result;
      const embed = new MessageEmbed({
        description: `${message.author.toString()} needs help with **${type}**
            *Here is some additional information:*
            ${info}`,
      });
      message.channel.send({ embed });
    },
  });
};

Terms and Conditions

This Repository only available for code look up and personal use.

You are not allowed to steal the code from this repository.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文