本文整理匯總了TypeScript中discord.js.Collection類的典型用法代碼示例。如果您正苦於以下問題:TypeScript js.Collection類的具體用法?TypeScript js.Collection怎麽用?TypeScript js.Collection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了js.Collection類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
channel.fetchMessages({ limit: numberOfMessages }).then((messages: Collection<string, Message>) => {
messages.forEach((message: Message) => {
message.delete()
})
channel.send(`Pruning ${numberOfMessages - 1} messages!`)
.then((reply: Message) => {
reply.delete(3000)
}
)
})
示例2: pickN
function pickN(users: Collection<string, GuildMember>, n: number): string {
const guildMembers = users.array().filter(member => !member.user.bot && member.user.presence.status === "online");
if (guildMembers.length === 0)
return `There are no users in the specified channel.`;
else if (n > guildMembers.length)
return guildMembers.map(member => ` - ${member.displayName}#${member.user.discriminator}`).join("\n");
else {
// Taken from https://jsperf.com/k-random-elements-from-array/2
let result: GuildMember[] = new Array(n);
let taken = new Array(n);
let len = guildMembers.length;
while (n--) {
const randNum = Math.floor(Math.random() * len);
console.log(`RAND: ${randNum}`);
const toAdd = guildMembers[randNum];
result[n] = guildMembers[randNum in taken ? taken[randNum] : randNum];
taken[randNum] = --len;
}
return result.map(member => ` - ${member.displayName}#${member.user.discriminator}`).join("\n");
}
}
示例3: postCheck
public postCheck(reaction: MessageReaction, user: User): string {
this.users.set(user.id, user);
if (this.options.max && ++this.total >= this.options.max) { return 'limit'; }
if (this.options.maxEmojis && this.collected.size >= this.options.maxEmojis) { return 'emojiLimit'; }
if (this.options.maxUsers && this.users.size >= this.options.maxUsers) { return 'userLimit'; }
return null;
}