【发布时间】: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。