user8442424
user8442424

Reputation:

How would I make my Python Discord bot mimic all messages sent?

I am writing a Discord bot using Python (v. 3.6.1). One of its functions detects all messages sent in a channel, processes them, and then responds to the messages in said channel. (At least, that's what I want it to do.)

I have tried this:

@bot.event
async def on_message(message):
    await bot.say(message.content)

The function responds when a message is sent, but not in the way that I want it to. I instead get an error:

discord.errors.InvalidArgument: Destination must be Channel, PrivateChannel, User, or Object. Received NoneType

How would I fix this? Many thanks!

Upvotes: 1

Views: 2154

Answers (1)

Benjin
Benjin

Reputation: 3497

You cannot use bot.say outside of a command.

Can I use bot.say in other places aside from commands?

No. They only work inside commands due to the way the magic involved works.

http://discordpy.readthedocs.io/en/latest/faq.html#can-i-use-bot-say-in-other-places-aside-from-commands

To have the bot repeat every message sent, you can use send_message. Below is an example.

@client.event
async def on_message(message):
    await client.send_message(message.channel, message.content)

Upvotes: 1

Related Questions