Simple Express.js-based API that retrieves Discord user information using a user ID.
- Node.js v14 or later
- A Discord Bot Token (with sufficient permissions)
- Caddy (if you want to set up a reverse proxy)
Returns a simple welcome message.
Discord Id Lookup
Retrieves Discord user information based on the provided Discord user ID.
id
- The Discord user ID.
Returns the JSON response from the Discord API, such as:
{
"id": "123456789012345678",
"username": "example",
"avatar": "avatar_hash",
"discriminator": "1234",
...
}
To run the server behind Caddy, follow these steps:
-
Install Caddy (if not already installed). Refer to the official installation guide.
-
Create a
Caddyfile
in the project directory with the following configuration:discord.example.com { reverse_proxy localhost:3000 }
-
Run Caddy:
caddy run
Your API will now be accessible at
https://discord.example.com
after you have run the program with nodejs.
Here's an example of making a request to the API using fetch
:
const fetch = require("cross-fetch");
async function getDiscordUser(discordId) {
const apiUrl = "http://localhost:3000/id/" + discordId;
try {
const response = await fetch(apiUrl);
if (response.ok) {
const data = await response.json();
console.log("User Data:", data);
} else {
console.error("Error:", response.status, await response.text());
}
} catch (error) {
console.error("Request failed:", error);
}
}
getDiscordUser("123456789012345678");