add new functions, move wait into functions

This commit is contained in:
Emily 2020-10-10 19:37:30 +11:00
parent cfa2f53f56
commit ca2a00b65c
2 changed files with 39 additions and 1 deletions

View file

@ -4,7 +4,7 @@ module.exports = class {
}
async run () {
await this.client.wait(1000);
await this.client.functions.wait(1000);
this.client.user.setActivity(`BNA | v${this.client.package.version}`, { type: "WATCHING" }) // lol
this.client.logger.ready(`Connected to Discord as ${this.client.user.tag}`);
}

View file

@ -72,6 +72,44 @@ class Functions {
return false;
}
}
searchForMembers (guild, query) {
if (!query) return;
query = query.toLowerCase();
var matches = [];
var match;
try {
match = guild.members.cache.find(x => x.displayName.toLowerCase() == query);
if (!match) guild.members.cache.find(x => x.user.username.toLowerCase() == query);
} catch (err) {};
if (match) matches.push(match);
guild.members.cache.forEach(member => {
if (
(member.displayName.toLowerCase().startsWith(query) ||
member.user.tag.toLowerCase().startsWith(query)) &&
member.id != (match && match.id)
) {
matches.push(member);
};
});
return matches;
};
findRole (input, message) {
var role;
role = message.guild.roles.cache.find(r => r.name.toLowerCase() === input.toLowerCase());
if(!role) {
role = message.guild.roles.cache.get(input.toLowerCase());
};
if(!role) return;
return role;
};
wait () {
require("util").promisify(setTimeout);
}
}
module.exports = Functions;