R
R
r1mple2021-08-07 17:15:56
Python
r1mple, 2021-08-07 17:15:56

Why does client.get_channel() return None?

client = discord.Client()

async def my_background_task():
    await client.wait_until_ready()
    counter = 0
    channel = client.get_channel(id)
    print(channel)
    while not client.is_closed():
        counter += 1
        await channel.send(counter)
        await asyncio.sleep(60) # task runs every 60 seconds

@client.event
async def on_ready():
    print('Logged in as')
    print(client.user.name)
    print(client.user.id)
    print('------')

client.loop.create_task(my_background_task())
client.run('token', bot=False)

Why is this happening? Google did not give answers, only said that they could not access the channel, why is that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WorldDev, 2021-11-01
@worldlight

In the code, everything seems to be correct. Here is the code for the recipient of the channel by ID.
channel = client.get_channel(id)Perhaps you entered the wrong channel ID that your bot is trying to receive. If you are sure that you entered the correct id, then I can’t help you with anything.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question