本文整理汇总了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;
}