Designcore
Designcore

Reputation: 1

Error: 'TextChannel' object has no attribute 'connect'

this is the code part:

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("")

This is the Error:

line 22, in on_message
voicechannel = await channel.connect()
AttributeError: 'TextChannel' object has no attribute 'connect

I've installed discord, opus, ffmpg, and a couple other things what should I do? please help

Upvotes: 0

Views: 412

Answers (1)

Łukasz Kwieciński
Łukasz Kwieciński

Reputation: 15689

As the error states, you're trying to connect to a text channel, you only can to voice channels. Instead of:

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

Use the Guild.voice_channels attribute

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

Upvotes: 1

Related Questions