Skip to content

Instantly share code, notes, and snippets.

@wiesty
Created March 7, 2024 23:17
Show Gist options
  • Save wiesty/8097b0327dc2fef96ebe990d87ef37c6 to your computer and use it in GitHub Desktop.
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.)
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);
});
}
@wiesty
Copy link
Author

wiesty commented Mar 7, 2024

add a .env file:

TOKEN=
WEBHOOK_URL=

run:
npm install axios dotenv
and run:
node index.js

@C0rn3j
Copy link

C0rn3j commented Oct 26, 2024

npm install axios dotenv actually

@wiesty
Copy link
Author

wiesty commented Oct 27, 2024

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