Created
March 7, 2024 23:17
-
-
Save wiesty/8097b0327dc2fef96ebe990d87ef37c6 to your computer and use it in GitHub Desktop.
Discord v10 personal (Token based) Api call to update the personal status. (After update it sends an webhook.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('dotenv/config'); | |
const axios = require('axios'); | |
let data = JSON.stringify({ | |
"status": "dnd" | |
// ('invisible', 'online', 'idle', 'dnd')." | |
}); | |
let config = { | |
method: 'patch', | |
maxBodyLength: Infinity, | |
url: 'https://discord.com/api/v10/users/@me/settings?', | |
headers: { | |
'Authorization': process.env.TOKEN, | |
'Content-Type': 'application/json', | |
}, | |
data : data | |
}; | |
axios.request(config) | |
.then((response) => { | |
sendDiscordWebhook("current status: " + response.data.status); | |
console.log(JSON.stringify(response.data.status)); | |
}) | |
.catch((error) => { | |
sendDiscordWebhook(error); | |
}); | |
function sendDiscordWebhook(text) { | |
let webhookData = JSON.stringify({ | |
"content": text | |
}); | |
let webhookConfig = { | |
method: 'post', | |
url: process.env.WEBHOOK_URL, | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
data : webhookData | |
}; | |
axios.request(webhookConfig) | |
.then((response) => { | |
console.log(JSON.stringify(response.data)); | |
}) | |
.catch((error) => { | |
console.log(error); | |
}); | |
} |
npm install axios dotenv
actually
npm install axios dotenv
actually
True, I installed it globally, forgot that. 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
add a .env file:
run:
npm install axios dotenv
and run:
node index.js