Rapptz / discord.py

An API wrapper for Discord written in Python.
http://discordpy.rtfd.org/en/latest
MIT License
14.88k stars 3.76k forks source link

AttributeError: 'generator' object has no attribute 'start' #107

Closed jzburda closed 8 years ago

jzburda commented 8 years ago

I'm trying to use a bot to pull from a Soundcloud link, but it keeps giving me this:

Traceback (most recent call last):
  File "C:\Users\jzbur\AppData\Local\Programs\Python\Python35\lib\site-packages\discord.py-0.10.0a0-py3.5.egg\discord\client.py", line 283, in _run_event
    yield from getattr(self, event)(*args, **kwargs)
  File "C:\Users\jzbur\AppData\Local\Programs\Python\Python35\LuneBotSera.py", line 36, in on_message
    player.start()
AttributeError: 'generator' object has no attribute 'start'

Here's my code:

import discord
import asyncio
import youtube_dl
client = discord.Client()
voice = None

@client.event
async def on_ready():
    print('Logged in')
def get_player( server, name ):
    for user in server.members:
        if ( user.name.lower().find( name ) != -1 ):
            return user
    return None

def get_channel(server, name, voice):
    for channel in server.channels:
        if (channel.name.lower().find( name ) != -1 ):
            if( voice and str(channel.type) != "voice"): continue
            return channel
    return None

@client.event
async def on_message(message):
    Args = message.content.lower().split(" ")
    if message.tts or message.content.startswith("/"):  await client.delete_message( message );
    if Args[0] == '/connect':
        Channel = get_channel( message.server, Args[1], True);
        if (Channel):
            #global voice
            if voice: await voice.disconnect();
            voice = await client.join_voice_channel( Channel );
    if Args[0] == '/play':
        global voice
        player = voice.create_ytdl_player( Args[1] )
        player.start()

    if Args[0] == '/game':
        Name = discord.Game()
        Name.name = message.content[6:]
        await client.change_status(Name, False)
print('Loading')
discord.opus.load_opus("libopus-0.x64.dll")
client.run('username', 'password')

Note client.run() has been omitted for privacy reasons.

Rapptz commented 8 years ago

player = await voice.create_ytdl_player(...).

ytdl_player was changed into a coroutine (and only that one, the rest aren't coroutines) so info retrieval doesn't block.

See https://github.com/Rapptz/discord.py/commit/1cd3c0b5cb9c1ae423c771cc1ffceb73d08b6158

jzburda commented 8 years ago

That was giving me a headache, thanks for the quick reply