Rapptz / discord.py

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

How do I send messages to a specific channel? #654

Closed ghost closed 7 years ago

ghost commented 7 years ago

I'm trying to make a bot that every thirty seconds it sends a piece of text to #bot-commands. How would I do this?

Code: import discord import time client = discord.Client() time.sleep(30) channel.send(ChannelIDHere,'Hello') client.run('mytokenboi') Nothing gets sent.

Note: it is a selfbot.

Thanks!

PapyrusThePlant commented 7 years ago

This example along with this faq entry

Hackmastr commented 7 years ago

Read this: http://discordpy.readthedocs.io/en/latest/faq.html?highlight=sleep#what-does-blocking-mean

Don't use time.sleep, instead use asyncio.sleep.

ghost commented 7 years ago

Now getting syntax errors import discord import asyncio client = discord.Client() await [redtext]asyncio[/redtext].sleep(30) channel.send((discord.Object(id='12324234183172'), 'Hello') client.run('token')

Hackmastr commented 7 years ago

Please use code tags/markup.

What Python version are you running?

Eternity71529 commented 7 years ago

read what @PapyrusThePlant said

liampwll commented 7 years ago

await [redtext] asyncio [/redtext].sleep(30)

ghost commented 7 years ago

Someone close this, ty!

ghost commented 7 years ago

wait i can i never realised

OlexiiZinik commented 5 years ago

await client.send_message(discord.Object(id='1234567890'), 'hello')