0
votes

I recently started to learn python by making bots for Discord. Now I'm making a Music bot but I got an error and couldn't find where the error is. Can you guys help, please? It joins the channel but gives the Error3 in Chat and if I write !Play (URL) again, it gives the Error 4 in chat.

Here is the Code:

import discord

client = discord.Client ()

@client.event
async def on_ready():
    print(client.user.name)
    print("-------------------")

@client.event
async def on_message(message):
    if message.content.startswith("!stop"):
        try:
            voice_client = client_voice_in(message.server)
            await voice_client.disconnect()
        except AttributeError:
            await client.send_message(message.channel, "I'm not connected.")
        except Exception as Hugo:
            await client.send_message(message.channel, "Error1_______|type|_______".format(type=Hugo))

    if message.content.startswith("!play"):
        try:
            yt_url = message.content[6:]
            if client.is_voice_connected(message.server):
                try:
                    voice = client.voice_client_in(message.server)
                    players[message.server.id].stop()
                    player = await voice.create_ytdl_player(yt_url, before_options=" -reconnect 1 -reconnect_streamed 1"
                                                                                   " -reconnect_delay_max 5")
                    players[message.server.id] = player
                    player.start()
                except Exception as e:
                    await client.send_message(message.server, "Error2______[Error]".format(error=e))

            if not client.is_voice_connected(message.server):
                try:
                    channel = message.author.voice.voice_channel
                    voice = await client.join_voice_channel(channel)
                    player = await voice.create_ytdl_player(yt_url, before_options=" -reconnect 1 -reconnect_streamed 1"
                                                                                   " -reconnect_delay_max 5")
                    players[message.server.id] = player
                    player.start()
                except Exception as e:
                    await client.send_message(message.channel, "Error3____[error]".format(error=e))
        except Exception as e:
            await client.send_message(message.channel, "Error4________[error]".format(error=e))




client.run("I erased the token number before sharing, it's not the problem")
1
It seems like you have it give you the error type when it errors. What types of errors are you getting?Qwerty
@Qwerty in discord chat it gives the error i named „Error3“ when i write !play and gives error when i write !stop as well but nothing in the python windowTayfun
by any chance are you following a tutorial? It appears that you except the Exception as e, and format e into the message. So what does e come out out be?Qwerty
@Qwerty i followed a german tutorial on youtube, youtu.be/rvbwoQF7Njw he made it work but i couldnt figure out my mistakeTayfun
a few things, did you download ffmpeg? Also you can see his code here gist.github.com/Grewoss/b6f0a99e135f73ff695bb096f140453e and compare it with your own.Qwerty

1 Answers

3
votes

You have not yet defined the variable players. At the beginning of your code, add this:

players = {}

Hope this worked!