UNPKG

discord-vatron

Version:

Módulo para facilitar la interacción con la API de Discord

43 lines (35 loc) 1.41 kB
const tipos = require('../../props.js').tiposCanales; const request = require('request-promise-native'); const { errores } = require('../../props.js'); module.exports = class Canal { constructor(datos, bot) { this._datos = datos; this.bot = bot; this.nombre = datos.name; this.id = datos.id; this.tipo = tipos[datos.type]; } eliminar() { const promesa = new Promise((resolve, reject) => { const c = this; request.delete({ url: `https://discord.com/api/v9/channels/${this.id}`, headers: { Authorization: 'Bot ' + this.bot.token } }) .then(() => { resolve(c); }) .catch(err => { //const json = JSON.parse(err.message.slice(err.message.indexOf('"')+1, -1).replace(/\\/g, '')); reject('[DISCORD-VATRON] ' + errores[err.statusCode] || err.message); }); }); return promesa; } get servidor() { return this.bot.servidores.has(this._datos.guild_id) ? this.bot.servidores.get(this._datos.guild_id) : null; } get categoria() { return this.tipo != 'categoria' ? this.servidor.canales.has(this._datos.parent_id) ? this.servidor.canales.get(this._datos.parent_id) : null : null; } toString() { return `<#${this.id}>`; } }