0

I need to write some messages in discord with my bot, but I don't know how to do it. It seems that discord.py can't send messages autonomously. Does anyone know how to do it?

tommyzan
  • 28
  • 1
  • 5
  • Create a background task. See here: https://stackoverflow.com/questions/54495679/how-to-make-a-loop-in-discord-py-rewrite/54501491#54501491 – Benjin Oct 18 '19 at 22:15

3 Answers3

0

It looks like a discord bot is meant to send only in response to something like a message, or some reaction.

Here is the documentation for the events it can respond to: https://discordpy.readthedocs.io/en/latest/api.html#discord-api-events

What are you trying to do? Send a message every hour? Message a user when they log in?

shanecandoit
  • 581
  • 1
  • 3
  • 11
0

I solved putting a while loop inside the function on_message. So I need to send only a message and then my bot can write as many messages as he wants

tommyzan
  • 28
  • 1
  • 5
0

There are different ways to send a message using a discord bot, this can be done through an event(check the documentation for event.

I'm going to make an event example. Let's make it so that when the bot is ready, it should send the message in that specific channel.

@client.event
async def on_ready():
    logs_channel = client.get_channel(CHANNEL_ID)
    await logs_channel.send("Bot is up and running")

Put your channel ID in the parenthesis and then it should work. You can do much more of course but that's just an example.

Now if you want to make it a command use the following code. Of course, that is very basic, you can do much more.

@client.command()
async def connor(ctx):
    await ctx.send("connor is a nerd")

Don't hesitate to comment if you need more.