Get a random user from server discord.js - javascript

How do you pick a random user from a server that a bot is in?
For example, GiveawayBot randomly picks a user in a giveaway. How can I implement that but without having to click on a reaction for the giveaway?
Also an example, #r in a command in Minecraft.

Array.from(message.member.guild.members)
This will get you an array of all members in a guild (with their id). I would recommend doing something else as it would take a lot of space to store larger servers in cache but it's up to you.
After doing so you can make a random number generator from 0 to the greatest amount and you will get an object of the user back when indexed, with the id as the identifier.

Related

Discord.js Antiraid bot (detect botwave)

I'm currently working on an Discord Antiraid bot that should detect when a server is raided by user accounts. Currently i just put each member in an array and remove this member after 10 seconds. If the array length is more than 10 it is a raid and all users in this array are getting banned. However, i am not completely satisfied with this method. Does anyone have any other suggestions for me?
Check how new the accounts are, check if they have default profile pictures, check if they have anything in common (status, profile picture, etc).

(discord.js/discord js) Is there a way to store current channel/category permissions and then reapply after an event?

Backstory
So, basically what I'm trying to do is using YT, I saw a lockdown command that locks down every channel in the guild once we type "!lockdown" by overwriting the channel permissions for certain roles but if we unlock the channels, everyone is able to type in other channels as permission gets overwritten to SEND message.
Trying to achieve
What I'm trying to achieve is that once we type "!lockdown", it stores the current permissions and then reapply them after I type "!unlock", I'm pretty sure it's possible but I can't figure out how. Any sorts of help will be appreciated!
Thanks in advance!
You may store the permissions of each channel in an object or an array or a database (more efficiency since the bot can be offline between both !lockdown and !unlock).
Then get the datas by a key as the id of each channel to get their permissions and do waht you want.

Discord.js: how do I get all the users who react to a message with a specific emoji, then set the list of users to a variable?

everyone! I am here because I am making a command that behaves in the style of GiveawayBot: getting all users who react to a particular message, and picking random users from what users were found.
However, I am unsure on how I can go about this in discord.js. I plan to have the command ask for the message ID, the amount of users to pick, and the emoji the users should have reacted to.
Can I get some help on doing this? Thanks in advance!
You have no less than a few options:
Listen to messageReactionAdd event to count up reactions as they happen live (and, possibly, messageReactionRemove).
Use message.awaitReactions or message.createReactionCollector to query for your reactions of interest.
[re-]fetch the individual message via channel.fetchMessage and peek through its .reactions.

How can I count the number of messages in one channel of each user?

I want to code a discord bot with the discord.js ... But in the documentation, I don't found a function to count the number of messages in a channel of each user... Is there a function to use the searchbar with filters like an user?
The search is not ( yet ) avaible for Bots.
You could Channel#fetchMessages but this would be very Api intensive.
Best way would be to get a database and increment it when the user sends a message, but that will only count messages when the bot is running.
The above works. But if you did not implement the feature into the bot. One way is to do a search using in: channel(whatever channel you want) and it will show you the result count which is technically the message count in that channel. Hope it helped.

How to get telegram bot user registered date via node.js?

How to get telegram bot user registered date in telegram via node.js?
I couldn't find any method in telegram bot api ref!
bot.on('message', (msg) => {
console.log(msg);
});
same as this bot: Robot Link
Unfortunately, there have no way to get this data from Telegram for now :(
Quote from previous /START message (from the bot you mentioned):
How it works
To quote #Superuser27: Interpolation on known registration dates of certain IDs.
The bot just has a large list of Account's IDs and their associated (known) creation dates and compares your id against this list.
My account creation date is wrong
Sure. That is why there is a "~" in front of it cutie. It is just a guess and very often the IDs given out at a time differ very much from each other, resulting in a sheer data mess. So just consider the date as some sort of art.
EDIT:
This message can be found here.

Categories