Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do i send a message in a specific channel when my bot start

I would like to send a message in a channel when my bot starts here is my code

@client.event
async def on_ready():
    print("Bot is running")
    activity = discord.Game(name="!test", type=3)
    await client.change_presence(status=discord.Status.idle, activity=activity)
    #issue starts here
    client.getchannel(944607968211652631)
    await client.channel.send("I am online")

I have tried a different way aswell

async def on_ready():
    print("Bot is running")
    activity = discord.Game(name="!test", type=3)
    await client.change_presence(status=discord.Status.idle, activity=activity)
    on = client.getchannel(944607968211652631)
    await on.channel.send("I am online")

but this also has not worked

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Instead of using client.getchannel which doesn’t exist, use Client.get_channel. It returns a channel which can be used to send messages.
Example:

channel = client.get_channel(id)
await channel.send("hi i've started")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading