Ad
How To Create Multiple Discord Bot Statuses With Javascript
I want to add something so after it plays the block from the API, I want it to be playing another status. For example, if it plays the block for some mins then it changes to playing something like "hello world", then it changes back to playing block after few mins. Below is the code I currently have:
function updateBlock() {
let response3 = axios.get(`https://google/api/getblockcount`)
.then((response3) => {
return Promise.resolve(response3);
}).catch((error) => {
console.log("Can not connect to API");
console.log(error);
return Promise.resolve({
failed: true
})
});
response3.then((response3)=> {
if (response3.failed) {
console.log("API Response Failed");
return response3;
}
let b = response3.data;
try {
Client.user.setActivity("B: " + b, { type: 'WATCHING' })
.then()
.catch(console.error);
} catch(err) {
console.log("This is an API error catch");
console.log(err);
}
});
}
Client.on("ready", () => {
console.log(botName + " online!");
updateBlock();
setInterval(() => {
updateBlock();
}, 10000);
});
Ad
Answer
Let's assume you are using discord.js library, this is how to display a random item from array textList
in which is also block height received from API, changing every 1min.
client.on('ready', () => {
setInterval(async ()=>{
let {data: blocks} = await axios.get('https://chain.ragnaproject.io/api/getblockcount').catch(console.log)
let textList = ['Hello World','Lorem Ipsum','Discord Bots', 'Blocks: ' + blocks]
var text = textList[Math.floor(Math.random() * textList.length)];
client.user.setActivity(text , { type: 'WATCHING' })
},60000) // milliseconds
});
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad