Skip to content

Commit

Permalink
Update 1.3.0 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
Smaug6739 committed Aug 8, 2021
1 parent e7f863b commit 36140a7
Show file tree
Hide file tree
Showing 11 changed files with 414 additions and 162 deletions.
197 changes: 134 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,145 @@
# Discord-resolve

This module groups together functions to retrieve data from different types of arguments. The functions group together all the possible cases each time (id, mention, name, start of name, name + tag).
This module groups together functions to retrieve data from different types of arguments. The functions group together all the possible cases each time (id, mention, name, start of name, name + tag). This module can also be used with slash-commands to give several options to a user.

## Getting Started

Prerequisites

Node.js 16.6.0 or newer is required.

### Instalation

With npm :

```sh-session
npm install discord-resolve
```

With yarn :

```sh-session
yarn add discord-resolve
```

## Usage

Create a new instance of DiscordResolve with the client has a parameter. Example : `const resolve = new DiscordResolve(client)`.

### Methods

- `resolveUser(arg)` : Get a user.
Parameter :
- arg : Id, mention, name, start of name, name + discriminator. (string)

Return : User or undefined

- `resolveGuild(arg)` : Get a guild.
Parameter :
- arg : Name or id of guild. (string)

Return : Guild or undefined

- `resolveMember(guild, arg)` : Get a guild member.
Parameter :
- guild : The guild (Guild)
- arg : Id, mention, username, start of username. (string)

Return : Member or undefined

- `resolveChannel(guild, arg)` : Get a guild channel.
Parameter :
- guild : The guild (Guild)
- arg : Id, mention, name, start of name. (string)

Return : GuildChannel or undefined

- `resolveRole(guild, arg)` : Get a guild role.
Parameter :
- guild : The guild (Guild)
- arg : Id, mention, name, start of name. (string)

Return : Role or undefined

- `resolveGuildEmoji(guild, arg)` : Get a guild emoji.
Parameter :
- guild : The guild (Guild)
- arg : Id, name, emoji. (string)

Return : GuildEmoji or undefined

- `resolveModo(member)` : Check if user is modo.
Parameter :
- member : GuildMember

Return : Boolean or undefined
Import the module from node_modules :

With CommonJS syntax :

```js
const { DiscordResolve } = require("discord-resolve");
```

With module syntax :

```js
import { DiscordResolve } = from 'discord-resolve';
```

Create a new instance of DiscordResolve with the client has a parameter.

```js
const resolve = new DiscordResolve(client)`.
```

## Methods

---

## [async] resolveUser(arg)

Get a user and fetch discord if it is not in the cache.

Parameters :

- arg : Id, mention, name, start of name, name + discriminator. (string)

Return : User or undefined

## resolveGuild(arg)

Get a guild in common with the bot.

Parameters :

const {DiscordResolve} = require('discord-resolve');
const {Client, Intents} = require('discord.js');
- arg : Name or id of guild. (string)

Return : Guild or undefined

## [async] resolveMember(guild, arg)

Get a guild member and fetch discord if it is not in the cache.

Parameters :

- guild : The guild where is the member (Guild)
- arg : Id, mention, username, start of username. (string)

Return : GuildMember or undefined

## resolveChannel(guild, arg)

Get a guild channel from a guild.

Parameters :

- guild : The guild where is the channel (Guild)
- arg : Id, mention, name, start of name. (string)

Return : GuildChannel or undefined

## resolveRole(guild, arg)

Get a guild role.

Parameters :

- guild : The guild (Guild)
- arg : Id, mention, name, start of name. (string)

Return : Role or undefined

## resolveGuildEmoji(guild, arg)

Get a emoji from a guild.

Parameters :

- guild : The guild where is the emoji (Guild)
- arg : Id, name, emoji (mention). (string)

Return : GuildEmoji or undefined

## resolveModo(member)

Check if user have a moderator permissions (ADMINISTRATOR, MANAGE_GUILD or BAN_MEMBERS).

Parameters :

- member : GuildMember

Return : Boolean

## Example

```js
const { DiscordResolve } = require("discord-resolve");
const { Client, Intents } = require("discord.js");
const client = new Client({intents:Intents.NON_PRIVILEGED});
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});
const util = new DiscordResolve(client);
client.on('message', async msg => {
const args = msg.content.split(' ');
const user = await util.resolveUser(args[0]) // args[0] accept id, mention, name, start of name and username + discriminator.
const guild = util.resolveGuild(args[1]) // args[1] accept id, and name.
const member = await util.resolveMember(msg.guild, args[2]) // args[2] accept id, mention, username, start of username.
const channel = util.resolveChannel(msg.guild, args[3]) // args[3] accept id, mention and name.
const role = util.resolveRole(msg.guild, args[4]) // args[4] accept id, mention, name and start of name.
const emoji = util.resolveGuildEmoji(msg.guild, args[5]) // args[5] accept id, name and emoji.
})
client.login('token')
client.on("message", async (msg) => {
const args = msg.content.split(" ");
const user = await util.resolveUser(args[0]); // args[0] accept id, mention, name, start of name and username + discriminator.
const guild = util.resolveGuild(args[1]); // args[1] accept id, and name.
const member = await util.resolveMember(msg.guild, args[2]); // args[2] accept id, mention, username, start of username.
const channel = util.resolveChannel(msg.guild, args[3]); // args[3] accept id, mention and name.
const role = util.resolveRole(msg.guild, args[4]); // args[4] accept id, mention, name and start of name.
const emoji = util.resolveGuildEmoji(msg.guild, args[5]); // args[5] accept id, name and emoji.
});
client.login("token");
```
4 changes: 2 additions & 2 deletions dist/index.js → lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class DiscordResolve {
* @param {string} arg The argument (id, name, emoji )
* @returns {GuildEmoji}
*/
this.resolveGuildEmoji = async (guild, arg) => {
this.resolveGuildEmoji = (guild, arg) => {
if (!guild || !arg)
return null;
const emoji = guild.emojis.cache.find((e) => e.id == arg || e.name == arg) ||
Expand All @@ -117,7 +117,7 @@ class DiscordResolve {
* @param {GuildMember} member
* @returns {boolean}
*/
this.resolveModo = async (member) => {
this.resolveModo = (member) => {
if (member.permissions.has('ADMINISTRATOR') || member.permissions.has('MANAGE_GUILD') || member.permissions.has('BAN_MEMBERS'))
return true;
return false;
Expand Down
Loading

0 comments on commit 36140a7

Please sign in to comment.