Предлагаю добавить возможность перехода в профиль Discord при нажатии на Username в профиле. Пример Открой меня Как это реализуемо? Открой меня У кажого юзера дискорд есть свой ID. Благодаря этому ID можно сделать ссылку которая будет открывать профиль пользователя в дискорде : https://discordapp.com/users/ID Например у меня ID 345556922440876032, ссылка для перехода в мой профиль выглядит так : https://discordapp.com/users/345556922440876032
RaysMorgan, нужен лишь токен бота discord, для отправки запроса на discord апишку, бот никак не должен быть связан с юзером, иметь общие сервера или авторизовываться через OAuth2
RaysMorgan, вот еще пример с HTML + CSS с беком NodeJS npm install express axios cors dotenv в .env токен бота BOT_TOKEN=MTIzMzI1MDE2NzQ4MzAxMTE3Mw.G5sOJN.qgeaWhJF75OHp8RWTv4VNAnfCj55qdja9jM-FU Code BOT_TOKEN=MTIzMzI1MDE2NzQ4MzAxMTE3Mw.G5sOJN.qgeaWhJF75OHp8RWTv4VNAnfCj55qdja9jM-FU index.html (там же и css) <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Get Discord Username</title> <style> body { font-family: Arial, sans-serif; background-color: #f0f0f0; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; } .container { background-color: white; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); text-align: center; width: 350px; } input { padding: 10px; width: 90%; border: 1px solid #ccc; border-radius: 4px; margin-bottom: 10px; } button { padding: 10px 20px; background-color: #7289da; color: white; border: none; border-radius: 4px; cursor: pointer; } button:hover { background-color: #5b6fa9; } .result { margin-top: 20px; word-wrap: break-word; } </style> </head> <body> <div class="container"> <h1>Get Discord Username</h1> <input type="text" id="userIdInput" placeholder="Enter Discord User ID"> <button onclick="getUsername()">Get Username</button> <div class="result" id="result"></div> </div> <script> async function getUsername() { const userId = document.getElementById('userIdInput').value.trim(); const resultDiv = document.getElementById('result'); if (!userId) { resultDiv.textContent = "Please enter a user ID."; return; } resultDiv.textContent = "Loading..."; try { const response = await fetch(`http://localhost:3000/api/user/${userId}`); if (response.ok) { const data = await response.json(); resultDiv.textContent = `Username: ${data.username}`; } else { const errorData = await response.json(); resultDiv.textContent = `Error: ${errorData.error}`; } } catch (error) { resultDiv.textContent = `Request failed: ${error.message}`; } } </script> </body> </html> HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Get Discord Username</title> <style> body { font-family: Arial, sans-serif; background-color: #f0f0f0; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; } .container { background-color: white; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); text-align: center; width: 350px; } input { padding: 10px; width: 90%; border: 1px solid #ccc; border-radius: 4px; margin-bottom: 10px; } button { padding: 10px 20px; background-color: #7289da; color: white; border: none; border-radius: 4px; cursor: pointer; } button:hover { background-color: #5b6fa9; } .result { margin-top: 20px; word-wrap: break-word; } </style> </head> <body> <div class="container"> <h1>Get Discord Username</h1> <input type="text" id="userIdInput" placeholder="Enter Discord User ID"> <button onclick="getUsername()">Get Username</button> <div class="result" id="result"></div> </div> <script> async function getUsername() { const userId = document.getElementById('userIdInput').value.trim(); const resultDiv = document.getElementById('result'); if (!userId) { resultDiv.textContent = "Please enter a user ID."; return; } resultDiv.textContent = "Loading..."; try { const response = await fetch(`http://localhost:3000/api/user/${userId}`); if (response.ok) { const data = await response.json(); resultDiv.textContent = `Username: ${data.username}`; } else { const errorData = await response.json(); resultDiv.textContent = `Error: ${errorData.error}`; } } catch (error) { resultDiv.textContent = `Request failed: ${error.message}`; } } </script> </body> </html> server.js const express = require('express'); const axios = require('axios'); const cors = require('cors'); require('dotenv').config(); const app = express(); const PORT = process.env.PORT || 3000; app.use(cors()); app.use(express.json()); const BOT_TOKEN = process.env.BOT_TOKEN; app.get('/api/user/:id', async (req, res) => { const userId = req.params.id; try { const response = await axios.get(`https://discord.com/api/v10/users/${userId}`, { headers: { 'Authorization': `Bot ${BOT_TOKEN}`, 'Content-Type': 'application/json' } }); const { username, discriminator } = response.data; res.json({ username: `${username}#${discriminator}` }); } catch (error) { if (error.response) { const { status, data } = error.response; if (status === 429) { res.status(429).json({ error: `Rate limited. Try again after ${data.retry_after} seconds.` }); } else if (status === 401) { res.status(401).json({ error: "Invalid token. Please check your bot token." }); } else if (status === 404) { res.status(404).json({ error: `User with ID ${userId} not found or bot has no access.` }); } else { res.status(status).json({ error: `Error ${status}: ${data.message || data}` }); } } else { res.status(500).json({ error: `Server error: ${error.message}` }); } } }); app.listen(PORT, () => { console.log(`Server is running on port ${PORT}`); }); JS const express = require('express'); const axios = require('axios'); const cors = require('cors'); require('dotenv').config(); const app = express(); const PORT = process.env.PORT || 3000; app.use(cors()); app.use(express.json()); const BOT_TOKEN = process.env.BOT_TOKEN; app.get('/api/user/:id', async (req, res) => { const userId = req.params.id; try { const response = await axios.get(`https://discord.com/api/v10/users/${userId}`, { headers: { 'Authorization': `Bot ${BOT_TOKEN}`, 'Content-Type': 'application/json' } }); const { username, discriminator } = response.data; res.json({ username: `${username}#${discriminator}` }); } catch (error) { if (error.response) { const { status, data } = error.response; if (status === 429) { res.status(429).json({ error: `Rate limited. Try again after ${data.retry_after} seconds.` }); } else if (status === 401) { res.status(401).json({ error: "Invalid token. Please check your bot token." }); } else if (status === 404) { res.status(404).json({ error: `User with ID ${userId} not found or bot has no access.` }); } else { res.status(status).json({ error: `Error ${status}: ${data.message || data}` }); } } else { res.status(500).json({ error: `Server error: ${error.message}` }); } } }); app.listen(PORT, () => { console.log(`Server is running on port ${PORT}`); });
Лично у меня ссылки на дискорд с айди не открывались вообще никогда (просто список друзей открывался), я хз почему, поэтому против
Ответ нашего кодера ., [02.10.2024 23:44] у меня кста не открывается модалка с его профилем ., [02.10.2024 23:44] она только для себя ворк ., [02.10.2024 23:44] я проверил ., [02.10.2024 23:45] если попробуешь в чужой профиль так зайти то не покажет