Discord REST API: get multiple users - discord

I'm trying to query multiple users with a single request by using the Discord REST API with Node.js and the Unirest Module.
unirest.get(`https://discord.com/api/v8/users/{user.id}`).headers({ Authorization: `Bot${botSecret}`})
.then(response =>{
console.log(response);
})
.catch(error =>{
console.error(error);
})
In order to get multiple users, I'm passing in the user.id field a list of ids in the following way:
"id1,id2,id3"
https://discord.com/api/v8/users/id1,id2,id3
However I get a 'Bad Request' response.
Which is the correct way to query multiple users with a single request??

I had a quick look around the Discord API & discord.js code it seems like they are done individually.
Discord's API doesn't seem to support getting multiple users at once & discord.js gets an array of users, and iterates through them whilst also checking cache, making sure they dont violate ratelimit, etc.

Related

Save value to Firestore on Stripe successful payment status

I want to write the user free-input form data to Firestore based on them successfully completing the Stripe checkout through the PaymentElement. I was first trying to do so based on the stripe.confirmPayment method response, which did not work well. Any ideas or practical examples on how can this be implemented? I have also tried using Stripe Webhooks, but I am unsure how to pass the user free-input form data there. Can this generally be handled from the front end, or should I create Firebase function?
const { error } = await stripe.confirmPayment({
elements,
confirmParams: {
return_url: window.location.href
}
});

Firebase GET request orderby 400 bad request

For a get request, I am trying to user order by like below but always get a 400 bad request. Here, multiple users can have multiple blog posts each with a unique id like b1 in screenshot below. The long sequence of characters is the uid of a user under blogs. Each user has their own uid.
https://assignment-c3557-default-rtdb.asia-southeast1.firebasedatabase.app/blogs.json?orderBy="createdAt"
I followed the documentation here
https://firebase.google.com/docs/database/rest/retrieve-data
All I am doing is issuing a simple GET request in react js as follows:
const resp = await fetch(`https://assignment-c3557-default-rtdb.asia-southeast1.firebasedatabase.app/blogs.json?orderBy="createdAt"``)
const data = await resp.json()
if(!resp.ok) { ... }
Below is the database single entry for schema reference
As I said in my previous comment, this URL is invalid:
https://assignment-c3557-default-rtdb.asia-southeast1.firebasedatabase.app/blogs.json/orderBy="createdAt"
                                                                                     ^
The query portion of a URL starts with a ? character.
https://assignment-c3557-default-rtdb.asia-southeast1.firebasedatabase.app/blogs.json?orderBy="createdAt"
                                                                                     ^
Firebase Realtime Database - Adding query to Axios GET request?
I followed the above similar issue resolution to solve my problem

DiscordJS - Fetch Multiple Users at Once

Instead if fetching every user by itself, I am trying to fetch an array of users at once.
This is the code I am trying to use:
var idsArr= ['682999909523259483','234269235071811584','503303866016727050'];
const membersArr = await interaction.guild.members.fetch({
idsArr,
});
console.log(membersArr);
Even though I only give it an array of 3 IDs, it logs every member of the server.
Any suggestion on how to fix that?
I just searched through official discord.js examples, and found this:
// Fetch by an array of users including their presences
guild.members.fetch({ user: ['66564597481480192', '191615925336670208'], withPresences: true })
.then(console.log)
.catch(console.error);
Maybe you should do this instead:
var idsArr= ['682999909523259483','234269235071811584','503303866016727050'];
const membersArr = await interaction.guild.members.fetch({
user: idsArr,
});
console.log(membersArr);
(Notice field name user instead of idsArr)

Discord API - Get a list of all the servers a bot is part of

I created a Discord bot that, once invited to a guild, is able to make API calls such as
GET/guilds/{guild.id}/members (https://discord.com/developers/docs/resources/guild#list-guild-members)
But how I do get the guild.id beforehand? Is it possible to make an API call to get a list of all the servers a bot is part of?
The client you create will have a guilds attribute you can use to access the servers it's in. This will be in the form of a GuildManager object which has a fetch() method to get a collection of guild objects.
Here is an example that gets all of a bot's guilds and prints their ids:
await bot.guilds.fetch()
.then(guilds => {
guilds.forEach(guild => {
console.log(guild.id);
});
});

discord.py get webhooks of channel

I'm trying to make a webhook so if anyone says 'ez' it deletes it and sends a message with the webhook with a random message. Originally what I was doing was
if "ez" in message.content:
webhook = await message.create_webhook(name=ctx.author.name)
await webhook.send(ezmessages[random.randint(0, len(ezmessages))-1], username=message.author.name, avatar_url=message.author.avatar_url)
await message.delete()
await webhook.delete()
but the problem is this gets rate limited if webhooks are created and deleted too quickly. So instead what I want to do is check if the bot already has a webhook for the text channel, and if there is one use that but if not use a different one. I thought this would work:
for webhook in message.channel.webhooks:
await webhook.send(ezmessages[random.randint(0, len(ezmessages))-1], username=message.author.name, avatar_url=message.author.avatar_url)
but I get the error
TypeError: 'method' object is not iterable
Even though it should return a list
Anyone know how to correctly iterate over this?
TextChannel.webhooks it's not an attribute, its a function and a coroutine, so you need to call it and await it
webhooks = await message.channel.webhooks()
for webhook in webhooks:
...
docs

Resources