user10122572
user10122572

Reputation:

Discord.py printing a invite link

I'm having an issue where i try to print a invite link into console, but instead it prints out

<generator object Client.create_invite at 0x000001D310A183B8>
<generator object Client.create_invite at 0x000001D310A65410>

i am using this code:

@client.event
async def on_ready():

    #await client.change_presence(game=Game(name="with humans"))
    print("Logged in as " + client.user.name)
    await asyncio.sleep(3)
    for server in client.servers:
        for channel in server.channels:
            channel_type = channel.type
            if str(channel_type) == 'text':
                invitelinknew = client.create_invite(destination=channel, xkcd=True, max_uses=100)
                print(str(invitelinknew))
                break

i tried changing print(invitelinknew) to print(str(invitelinknew)), but it didn't change the outcome

EDIT:

New errors when consuming the genrator with invitelinknew2 = list(invitelinknew) and print(invitelinknew2):

Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\site-packages\discord\client.py", line 307, in _run_event
    yield from getattr(self, event)(*args, **kwargs)
  File "C:/Users/Rasmus/Python/discordbot/botnoggi2.py", line 128, in on_ready
    invitelinknew2 = list(invitelinknew)
  File "C:\Program Files\Python36\lib\site-packages\discord\client.py", line 2628, in create_invite
    data = yield from self.http.create_invite(destination.id, **options)
  File "C:\Program Files\Python36\lib\site-packages\discord\http.py", line 137, in request
    r = yield from self.session.request(method, url, **kwargs)
  File "C:\Program Files\Python36\lib\site-packages\aiohttp\client.py", line 555, in __iter__
    resp = yield from self._coro
  File "C:\Program Files\Python36\lib\site-packages\aiohttp\client.py", line 202, in _request
    yield from resp.start(conn, read_until_eof)
  File "C:\Program Files\Python36\lib\site-packages\aiohttp\client_reqrep.py", line 640, in start
    message = yield from httpstream.read()
  File "C:\Program Files\Python36\lib\site-packages\aiohttp\streams.py", line 641, in read
    result = yield from super().read()
  File "C:\Program Files\Python36\lib\site-packages\aiohttp\streams.py", line 476, in read
    yield from self._waiter
AssertionError: yield from wasn't used with future
Future exception was never retrieved
future: <Future finished exception=ServerDisconnectedError()>
aiohttp.errors.ServerDisconnectedError

Upvotes: 2

Views: 1746

Answers (1)

Tristo
Tristo

Reputation: 2408

According to the documentation create_invite is a coroutine and requires the await keyword

Change your code to include it such as

if channel.type == discord.ChannelType.text:
  invitelinknew = await client.create_invite(destination=channel, xkcd=True, max_uses=100)
  print(invitelinknew.url)

Upvotes: 1

Related Questions