python - 错误:“TextChannel”对象没有“连接”属性
问题描述
这是代码部分:
import discord
import random from discord.utils
import get import time
class MyClient(discord.Client):
#Einloggen
async def on_ready(self):
print("Eingeloggt")
#Wenn Nachricht gepostet wird
async def on_message(self, message):
if message.author == client.user:
return
if message.content == "$help":
print("help")
if message.content.startswith("$play"):
where = message.content.split(" ")[1]
channel = get(message.guild.channels, name=where)
voicechannel = await channel.connect()
voicechannel.play(discord.FFmpegPCMAudio('triggered.mp3'))
client = MyClient()
client.run("")
这是错误:
line 22, in on_message
voicechannel = await channel.connect()
AttributeError: 'TextChannel' object has no attribute 'connect
我已经安装了 discord、opus、ffmpg 和其他一些东西,我该怎么办?请帮忙
解决方案
正如错误所述,您正在尝试连接到文本频道,您只能连接到语音频道。代替:
channel = get(message.guild.channels, name=where)
使用Guild.voice_channels
属性
channel = get(message.guild.voice_channels, name=where)
推荐阅读
- ruby-on-rails - 从应用程序中删除观察者后未初始化的常量 VideoObserver 错误
- java - 在 SQLite 数据库中设置默认值
- javascript - JSON.parse 中位置 0 处的 JSON 中的意外令牌 <
- react-native - 不变违规:元素类型无效:预期使用 react-redux 连接的字符串
- python - 如何使用下划线访问库中的函数?
- c - 解码后的 shellcode 不执行:非法指令:4
- r - 为什么我的时差不能基于 if 函数在 for 循环中工作?
- javascript - 使用可以恢复丢失事件的 RxJS 轮询
- traefik - 是否可以让 Traefik 处理多个证书/域
- python - 为什么这两个约束导致我的 LP 模型在 Gurobi 中不可行?