![](/img/trans.png)
[英]Discord.py: wait_for('reaction_add') not working as intended
[英]discord.py wait_for not working in a method
在這種情況下,我有 2 個單獨的文件,其中 1 個用於主文件,另一個是包含函數的文件(不在 Cog 中)。 我想讓用戶響應機器人輸出的消息,然后機器人將該消息發送回聊天中。
這里的問題是程序沒有注冊一個人輸入的消息,我嘗試使用self.bot
或client
而不是只使用 bot 用於wait_for
function,但這不起作用。
這是我的main.py
文件的代碼
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)
這是我的anime.py
代碼,它是一個單獨的文件
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")
bot 根本沒有在您的anime.py
中定義,您可以將其作為參數傳遞給function。
await search_anime(bot, ctx, query)
async def search_anime(bot, ctx, query)
#other stuff
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.