Motivation command no longer works
IMPORTANT : DO NOT SKIP THIS STEPS AND DO NOT DELETE THEM. WE CAN NOT HELP YOU IF YOU DO NOT PROVIDE INFORMATION AND STEPS TO REPRODUCE
Do not open an issue if you simply "copied" code over to your bot/another bot. This is absolutely not recommended and will cause bugs. Also do not open an issue if you modified code and added features and now it's not working right. This is because I can't figure it out and don't have the time to read your code and find out what you did wrong.
Describe the bug A clear and concise description of what the bug is. No longer returns anything due to domain expiring To Reproduce Steps to reproduce the behavior:
- Use 'motivation' command
Expected behavior A clear and concise description of what you expected to happen. Should return a motivational quote, which it was working as of the 15th, so it's a very recent problem Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: [e.g. Windows, Ubuntu...]: Debian 12
- Node.js Version(Should be v16 at least): 20.12.2
- Is python 2.7 installed?: No
- How are you hosting the bot(Locally, on a vps, heroku, glitch...): Locally
Additional context Add any other context about the problem here. It seems as if the site it uses has expired, and because of that no longer returns quotes
Any ideas for some alternative APIs? I have yet to find any, and it doesn't seem like this one is coming back
Any ideas for some alternative APIs? I have yet to find any, and it doesn't seem like this one is coming back
It looks like Zen Quotes might be a good replacement for the API used in this one.
Zen Quotes API Docs - Call Quotes
Should work the same way mostly. Just change the API URL to https://zenquotes.io/api/quotes/ and update the embed response accordingly.
This is a base example of the JSON structure Zen Quotes uses.
[{
"q": "Lack of emotion causes lack of progress and lack of motivation.",
"a": "Tony Robbins",
"i": "https://zenquotes.io/img/tony-robbins.jpg",
"c": "63",
"h": "<blockquote>“Lack of emotion causes lack of progress and lack of motivation.” — <footer>Tony Robbins</footer></blockquote>"
},
// ...MORE DATA... //
{
"q": "The friend is the man who knows all about you, and still likes you.",
"a": "Elbert Hubbard",
"i": "https://zenquotes.io/img/elbert-hubbard.jpg",
"c": "67",
"h": "<blockquote>“ The friend is the man who knows all about you, and still likes you.” — <footer>Elbert Hubbard</footer></blockquote>"
}]
If that API works, changing the motivation.ts file contents to this should work:
import { ApplyOptions } from '@sapphire/decorators';
import { Command, CommandOptions } from '@sapphire/framework';
import { EmbedBuilder } from 'discord.js';
@ApplyOptions<CommandOptions>({
name: 'motivation',
description: 'Replies with a motivational quote!',
preconditions: ['isCommandDisabled']
})
export class MotivationCommand extends Command {
public override registerApplicationCommands(
registry: Command.Registry
): void {
registry.registerChatInputCommand({
name: this.name,
description: this.description
});
}
public override async chatInputRun(
interaction: Command.ChatInputCommandInteraction
) {
try {
const response = await fetch('https://zenquotes.io/api/quotes');
const data = await response.json();
if (!data)
return await interaction.reply({ content: 'Something went wrong!' });
const randomQuote = data[Math.floor(Math.random() * data.length)];
for quote in randomQuote {
contents = data["q"],
author = data["a"],
image = data["i"]
};
const embed = new EmbedBuilder()
.setColor('Yellow')
.setAuthor({
name: 'Motivational Quote',
url: 'https://zenquotes.io',
iconURL: 'https://docs.zenquotes.io/wp-content/uploads/zen-quotes-icon-512.png'
})
.setDescription(`*"${quote.contents}*"\n\n-${quote.author}`)
.setThumbnail(quote.image)
.setTimestamp()
.setFooter({
text: 'Powered by zenquotes.io'
});
return await interaction.reply({ embeds: [embed] });
} catch {
return await interaction.reply({
content: 'Something went wrong!'
});
}
}
}
You might need to tweak it a little for indentation and so on. But, basically, the JSON fields simply need to be defined for this API to work.
If I'm not too rusty, the code above should have that done.
Alright, will try that sometime after I get up, stayed up way too late lol