I recently made a discord bot for testing and the bot was supposed to send a inspirational quote from a online database on a command. However, when I entered the command it doesnt seem to work.
I tried to troubleshoot the code, but I couldn't find what was wrong. The bot sends a message to my server and specific defined channel whenever I press run but that seems to be all it does. Example of what it does
This is my code:
import discord
from discord.ext import commands, tasks
import requests
intents = discord.Intents(messages=True, guilds=True)
bot = commands.Bot(command_prefix="?", intents=intents)
@bot.event
async def on_ready():
print("Bot is ready.")
quote.start()
@tasks.loop(hours=24)
async def quote():
response = requests.get("https://zenquotes.io/api/random")
json_data = response.json()
quote = json_data[0]["q"] + " -" + json_data[0]["a"]
channel = bot.get_channel(channel-id) # use your channel id here
await channel.send(quote)
@quote.before_loop
async def before_quote():
await bot.wait_until_ready()
print("Finished waiting")
@bot.command()
async def qod(ctx):
response = requests.get("https://zenquotes.io/api/random")
json_data = response.json()
quote = json_data[0]["q"] + " -" + json_data[0]["a"]
await ctx.send(quote)
bot.run(
"bot-token")
I am using repl.it to run my program and I am researching ways to keep it running nonstop.
If anything else is needed please let me know. Thank you for reading this.
Sorry if I made any mistakes, its my first time using stack.