【问题标题】:Error: 'TextChannel' object has no attribute 'connect'错误:“TextChannel”对象没有“连接”属性
【发布时间】:2021-05-03 19:38:40
【问题描述】:

这是代码部分:

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 和其他一些东西,我该怎么办? 请帮忙

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    由于错误状态,您正在尝试连接到文本频道,您只能连接到语音频道。而不是:

    channel = get(message.guild.channels, name=where)
    

    使用Guild.voice_channels 属性

    channel = get(message.guild.voice_channels, name=where)
    

    【讨论】:

    • 现在出现另一个错误:从无 discord.errors.ClientException 引发 ClientException(executable + ' was not found.'): ffmpeg was not found。如果我输入“pip install ffmpeg”,它会说 ffmpeg 已经存在
    • 这不是与您的问题相关的错误,
    • 你能帮我吗?
    • 可以,但是对discord.py语音了解不多,看this问题
    猜你喜欢
    • 1970-01-01
    • 2020-07-02
    • 1970-01-01
    • 2015-01-29
    • 2017-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-21
    相关资源
    最近更新 更多