【问题标题】:discord py music bot不和谐 py 音乐机器人
【发布时间】:2020-06-20 15:50:42
【问题描述】:
import discord
from discord.ext import commands
from discord.utils import get
import youtube_dl
from discord import FFmpegPCMAudio

@bot.command(pass_context=True)
async def join(ctx):
    channel = ctx.message.author.voice.voice_channel
    await client.join_voice_channel(channel)

@bot.command(pass_context=True)
async def leave(ctx):
    server = ctx.message.server
    voice_client = client.voice_client_in(server)
    await voice_client.disconnect()

@bot.command(pass_context=True)
async def play(ctx, url):
    guild = ctx.message.guild
    voice_client = guild.voice_client
    player = await voice_client.create_ytdl_player(url)
    players[server.id] = player
    player.start()

bot.run(TOKEN)

忽略命令连接中的异常: 回溯(最近一次通话最后): 文件“C:\Users\hahuibala\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py”,第 83 行,已包装 ret = 等待 coro(*args, **kwargs) 文件“C:\Users\hahuibala\Desktop\py\bot.py”,第 73 行,加入 频道 = ctx.message.author.voice.voice_channel AttributeError: 'NoneType' 对象没有属性 'voice_channel'

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

Traceback (most recent call last):
  File "C:\Users\hahuibala\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 892, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\hahuibala\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 797, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\hahuibala\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 92, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'voice_channel'

【问题讨论】:

  • 欢迎来到 Stack Overflow!请阅读how to ask

标签: python discord


【解决方案1】:

试试这个而不是那个

@bot.command()
async def join(ctx):
    channel = ctx.author.voice.channel
    await channel.connect()
@bot.command()
async def leave(ctx):
    await ctx.voice_client.disconnect()

【讨论】:

  • 你能解释一下吗?
猜你喜欢
  • 2019-04-04
  • 2019-02-26
  • 2018-08-24
  • 2019-08-03
  • 2021-11-24
  • 2020-09-23
  • 2021-05-23
  • 2021-09-30
  • 2020-10-08
相关资源
最近更新 更多