Issue
I have 2 separate files in this case, where 1 is for the main file, and another is a file containing functions(not in a Cog). I want to have a user respond to the message that a bot outputs and then the bot will send that message back into the chat.
The issue over here is that the program is not registering a message that a person inputs and I tried using self.bot
or client
instead of just bot for the wait_for
function, but that doesn't work.
Here is my code for my main.py
file
import discord
import asyncio
from discord.ext import commands
from anime import *
from embed import *
bot = commands.Bot(command_prefix="m.")
TOKEN = "INSERT TOKEN HERE"
@bot.event
async def on_ready():
print("Connected to discord")
@bot.command(name="searchanime", help="Seaches through the MAL Database to find an anime. Requires a Title to search")
async def search(ctx, *, query):
await search_anime(ctx, query)
bot.run(TOKEN)
Here is my code for anime.py
which is a separate file
import discord
import requests
headers = {
'x-rapidapi-key': "2ed26cb89emsh2b7cb079ec42fd9p15290cjsne485ef05078a",
'x-rapidapi-host': "jikan1.p.rapidapi.com"
}
async def search_anime(ctx, query):
url = "https://jikan1.p.rapidapi.com/search/anime"
querystring = {"q": query, "format": "json"}
response = requests.request("GET", url, headers=headers, params=querystring).json()
response_list = []
for i in range(4):
response_list.append(response["results"][i])
await ctx.send("Message 'm.(desired number)' without the parenthesis to select the anime you are looking for from this list")
for i in range(len(response_list)):
await ctx.send(f"{i+1}) {response_list[i]['title']}")
try:
msg = await bot.wait_for("message")
if msg:
await ctx.send(msg.content)
except asyncio.TimeoutError:
await ctx.send("Cancelling due to timeout")
Solution
bot is simply not defined in your anime.py
, you can pass it as a parameter to the function.
await search_anime(bot, ctx, query)
async def search_anime(bot, ctx, query)
#other stuff
Answered By - Ceres
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.