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'
答案 0 :(得分:0)
试试这个而不是那个
flutter: The method '[]' was called on null.
flutter: Receiver: null
flutter: Tried calling: []("name")