【发布时间】:2021-03-20 04:12:14
【问题描述】:
我查看了所有关于将 discord bot 连接到语音通道以播放声音的问题,但我找不到我需要的答案。我是 discord 库的新手,并没有解决事情是如何工作的,所以当我尝试在网站上给出答案时,我大多会收到这样的错误:
AttributeError: 'NoneType' object has no attribute 'channel'
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'channel'
我的代码如下所示:
import discord
from dotenv import load_dotenv
from discord.ext import commands
load_dotenv()
token = "XXXXXXXXXXXXXXXXX"
client = commands.Bot(command_prefix='.')
voice = discord.VoiceChannel
@client.command(name="join")
async def join(ctx):
channel = ctx.author.voice.channel
voice = get(self.bot.voice_clients, guild=ctx.guild)
if voice and voice.is_connected():
await voice.move_to(channel)
else:
voice = await channel.connect()
client.run(Token)
这只是其他发送或事件部分正在工作的代码的语音部分。
【问题讨论】:
-
我在 stackoverflow.com/q/62888711/10767584 线程上看到了这个 .join 命令。
标签: python python-3.x discord.py