client.on("message", message => {
if(message.content == `${prefix}onli`) {
message.channel.send(message.guild.members.cache.filter(member => member.presence.status === 'online' && 'dnd' && 'idle').forEach(member => message.channel.send(member.user.username))
)}})
const items = [
{
name: 'Apple',
dropChance: 0.7
},
{
name: 'Knife',
dropChance: 0.25
},
{
name: 'Spoon',
dropChance: 0.25
},
{
name: 'Ice Cream',
dropChance: 0.1
}
];
const lerp = (min, max, value) => ((1 - value) * min + value * max);
const drop = items => {
const total = items.reduce((accumulator, item) => (accumulator += item.dropChance), 0);
const chance = lerp(0, total, Math.random());
let current = 0;
for (const item of items) {
if (current <= chance && chance < current + item.dropChance) {
return item;
}
current += item.dropChance;
}
};
client.on('message', message => {
if (message.content.startsWith(`${prefix}drop`)) {
const item = drop([
{
name: 'Apple',
dropChance: 0.7
},
{
name: 'Knife',
dropChance: 0.25
},
{
name: 'Spoon',
dropChance: 0.25
},
{
name: 'Ice Cream',
dropChance: 0.1
}]);
// Вместо .name можно использовать любой другой ключ, по которому
// будет находится название предмета.
message.channel.send(`Выпало ${item.name}`);
}
})
Как-то так оно выглядит.