如何使 ctx 不是 'interaction' 类型(nextcord 斜杠命令)?

How do I make it so that ctx is not of type 'interaction' (nextcord slash commands)?

我正在尝试使用 nextcord 斜杠命令和交互创建音乐机器人。该命令尚未完全完成,因为我什至无法让它加入语音频道。我还不完全知道交互是如何工作的,但我假设它是一个与 ctx 类似的概念。下面是我的 music.py 齿轮:

import nextcord
from nextcord.ext import commands
from nextcord import Interaction

class Music(commands.Cog):
    def __init__(self, client):
        self.client = client

    guild_ids = ["Guild Ids Go Here"]

    #slash commands go under here
    @nextcord.slash_command(name="play", description="plays music in vc", guild_ids = guild_ids)
    async def play(self, interaction : Interaction, query: str):
        channel = interaction.author.voice.channel  #ERROR IS HERE
        try:
            await channel.connect()
            await interaction.response.send_message("The bot has joined vc.")
        except:
            await interaction.response.send_message("Failed to find voice channel.")


def setup(client):
    client.add_cog(Music(client))

我收到一条错误消息“'Interaction' 对象没有属性 'author'。它出现在 'play' 的第 15 行,当它说 'channel = interaction.author.voice.channel' 时。我认为这意味着这不是获取作者语音通道的正确方法。如果是这种情况,是否有更好的工作方法?

  1. nextcord interaction中,留言作者是interaction.user, 频道是 interaction.channel.

  2. 您也可以通过interaction.send发送互动消息 interaction.response.send_message 个。它更短更容易 阅读。

  3. 如果你想在不使用交互的情况下发送普通消息,试试 interaction.channel.send。类似于应用命令中的ctx.channel.send