python-3.x Discord机器人在收到命令时未播放音频

qni6mghb  于 2023-01-22  发布在  Python
关注(0)|答案(1)|浏览(154)

我使用python 3.6制作了一个discord机器人来播放音乐。每当我给它"play"命令时,discord应用程序显示机器人正在播放音频,但我听不到任何音频。我检查了设置并最大化了所有与音频相关的设置。当我返回pycharm时,我在"run"选项卡中看到这个错误:

Traceback (most recent call last):
  File "/Volumes/Mahmoud-Disk/MyProfile/Library/Python/3.8/lib/python/site-packages/discord/ext/commands/core.py", line 229, in wrapped
    ret = await coro(*args, **kwargs)
  File "/Volumes/Mahmoud-Disk/MyProfile/Desktop/Discord Bot/Discord-Bot/main.py", line 72, in play
    await ctx.send(embed = discord.Embed(
TypeError: __init__() got an unexpected keyword argument 'author'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Volumes/Mahmoud-Disk/MyProfile/Library/Python/3.8/lib/python/site-packages/discord/ext/commands/bot.py", line 1349, in invoke
    await ctx.command.invoke(ctx)
  File "/Volumes/Mahmoud-Disk/MyProfile/Library/Python/3.8/lib/python/site-packages/discord/ext/commands/core.py", line 1023, in invoke
    await injected(*ctx.args, **ctx.kwargs)  # type: ignore
  File "/Volumes/Mahmoud-Disk/MyProfile/Library/Python/3.8/lib/python/site-packages/discord/ext/commands/core.py", line 238, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: __init__() got an unexpected keyword argument 'author'

下面是我的代码:

import discord
from discord.ext import commands
import wavelink

client = commands.Bot(command_prefix = ".", intents = discord.Intents.all())

class CustomPlayer (wavelink.Player):

    def __init__(self):
        super().__init__()
        self.queue = wavelink.Queue()

@client.event

async def on_ready():
    client.loop.create_task(connect_nodes()) #HTTPS and Websocket operations

async def connect_nodes(): #Helper function
    await client.wait_until_ready()
    await wavelink.NodePool.create_node(
        bot = client ,
        host = "127.0.0.1" ,
        port = 2333 ,
        password = "yk I can't "
    )

@client.event
async def on_wavelink_node_ready(node = wavelink.Node):
    print(f"Node: <{node.identifier}> is ready!")

@client.command()
async def connect(ctx):
    vc = ctx.voice_client
    try:
        channel = ctx.author.voice.channel
    except AttributeError:
        return await ctx.send("Please join a channel to connect.")
    if not vc:
        await ctx.author.voice.channel.connect(cls = CustomPlayer())
    else:
        await ctx.send("The bot is already connected to a voice channel.")

@client.command()
async def disconnect(ctx):
    vc = ctx.voice_client
    if vc:
        await vc.disconnect()
    else:
        await ctx.send("Bot is not connected to a voice channel.")

@client.command()
async def play(ctx, *, search: wavelink.YouTubeTrack):
    vc = ctx.voice_client #represents a discord voice connection
    if not vc:
        custom_player = CustomPlayer()
        vc: CustomPlayer = await ctx.author.voice.channel.connect(cls = custom_player)

    if vc.is_playing():

        vc.queue.put(item = search)

        await ctx.send(embed = discord.Embed(
            title = search.title,
            url = search.uri,
            author = ctx.author,
            description = f"Queued {search.title} in {vc.channel}"
        ))
    else:
        await vc.play(search)

        await ctx.send(embed = discord.Embed(
            title = search.title,
            url = search.uri,
            author = ctx.author,
            description = f"Playing {vc.source.title} in {vc.channel}"))

我不知道该怎么做才能解决这个问题。

rsaldnfx

rsaldnfx1#

简单地说,我删除了

author = ctx.author,

两次

相关问题