PyCord Slashcommands:AttributeError:类型对象“交互”没有属性“响应”

问题描述 投票:0回答:1
今天我从 PyCord 2.4.1 更改为 2.6.0,我的整个机器人都坏了。 我收到错误消息:

Extension 'cogs.stats' raised an error: AttributeError: type object 'Interaction' has no attribute 'respond'
我用 

await ctx.response.send_message("example")

 发送回复。

有人不知道我需要改变什么才能让它再次工作吗?

这是main.py

import asyncio import log_helper import os import discord from discord.ext import commands from dotenv import load_dotenv bot = commands.Bot(intents=discord.Intents.all(), command_prefix="$$") log = log_helper.create("main") bot.help_command = None @bot.event async def on_ready(): await bot.change_presence(activity=discord.Game(name="Drachen Kult"), status=discord.Status.online) log("Bot ist Online!", "SUCCESS") async def load_extensions(): log("Lade Cogs...", "SYSTEM") for filename in os.listdir("cogs"): if filename.endswith(".py"): log(f"{filename} wird geladen!") try: await bot.load_extension(f"cogs.{filename[:-3]}") except Exception as e: log(f"Beim Laden von {filename} ist ein Fehler aufgetreten: {e}", "CRITICAL") log("Alle Cogs wurden geladen!", "SUCCESS") if __name__ == "__main__": load_dotenv() asyncio.run(load_extensions()) log("Starte Bot...", "SYSTEM") bot.run(os.getenv('TOKEN'))
这是测试.py

import discord from discord.ext import commands, tasks from discord.commands import slash_command import log_helper log = log_helper.create("Manager") load_dotenv() class Manager(commands.Cog): def __init__(self, bot): self.bot = bot @commands.Cog.listener() async def on_ready(self): Manager.bot = self.bot @slash_command(name="test") async def restart(self, ctx): await ctx.respond.send_message("Test!") def setup(bot): bot.add_cog(Test(bot))
我用 

ctx.respond.send_message

ctx.response.send_message
 测试了 ist,这两个给出了相同的错误。

python python-3.x discord pycord
1个回答
0
投票
要让机器人再次工作,请查找

Interaction.respond

 的任何用法并将其替换为 
ctx.response.send_message()

阅读 PyCord 2.6.0 文档也有帮助:)

试试这个

@bot.slash_command(name=“example”) async def example(ctx): await ctx.response.send_message(“Example is working!”)
测试一下,我希望你能让你的机器人再次工作

© www.soinside.com 2019 - 2024. All rights reserved.