所以我开始从事音乐机器人的工作,当我尝试离开时,我会不断得到它。加入语音频道效果很好。
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'disconnect'
我的代码是
@client.command(name = "join",
pass_context = True)
async def join(ctx):
channel = ctx.message.author.voice.voice_channel
await client.join_voice_channel(channel)
print("Bot joined the voice channel")
@client.command(name = "leave",
pass_context = True)
async def leave(ctx):
server = ctx.message.server
voice_client = client.voice_client_in(server)
await voice_client.disconnect()
print("Bot left the voice channel")
还使用以下库:
import discord
from discord.ext.commands import Bot
from discord.ext import commands
from discord import Game
import random
答案 0 :(得分:1)
如果该服务器中没有function change(thing) {
thing.value = thing.value + 1;
return thing;
}
let a = {value: 1};
console.log(change(a))
console.log(a)
,则Client.voice_client_in
将返回VoiceClient
。尝试断开连接之前,应先检查一下。
None
答案 1 :(得分:0)
@PatrickHaugh输入的固定版本为:
进口:
import discord
from discord.ext.commands import Bot
from discord.ext import commands
from discord import Game
from ctypes.util import find_library
import random
from discord import opus
import nacl
import asyncio
代码:
@client.command(name = "join",
pass_context = True)
async def join(ctx):
opus_path = find_library('opus')
discord.opus.load_opus(opus_path)
if not opus.is_loaded():
print('Opus was not loaded')
else:
channel = ctx.message.author.voice.voice_channel
await client.join_voice_channel(channel)
print("Bot joined the voice channel")
@client.command(name = "check",
pass_context = True)
async def check(ctx):
server = ctx.message.server
if client.is_voice_connected(server):
print("Yes")
else:
print("No")
@client.command(pass_context = True)
async def leave(ctx):
for x in client.voice_clients:
if(x.server == ctx.message.server):
return await x.disconnect()
return await client.say("I am not connected to any voice channel on this server!")