Created
August 26, 2019 18:09
-
-
Save alex-taxiera/6ac0d186ff91b1aed4be47361d2b0f78 to your computer and use it in GitHub Desktop.
Simple typing management for d.js v12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { | |
TextChannel, | |
DMChannel | |
} = require('discord.js') | |
function isTextBasedChannel (channel) { | |
return channel instanceof TextChannel || channel instanceof DMChannel | |
} | |
module.exports = function (channel, limit) { | |
if (!channel || !isTextBasedChannel(channel)) { | |
throw new TypeError('CHANNEL_TYPE') | |
} | |
if (ms && (isNaN(ms) || ms < 0) { | |
throw new RangeError('TYPING_LIMIT') | |
} | |
setTimeout(() => { | |
channel.stopTyping(true) | |
}, limit || 1000) | |
return channel.startTyping(Infinity) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment