Reputation: 1
so im making 2 discord bots: one will listen for commands and when it recieves one it will send a message in a private channel. when the first bot sends a message in that channel the second one will respond to indicate that it's online, then bot 1 requests to start a Minecraft server. the problem is, bot 2 only responds once and if I want it to respond more than once I need to manually restart the code. im on python 3.8.6
import discord
client = discord.Client()
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.author.id == bot 1 id:
if message.content.startswith('<@!bot 2 id>'):
starterChannel = client.get_channel('private channel')
channel = message.channel
if channel == starterChannel:
await channel.send('ye')
@client.event
async def on_message(message):
if message.content.startswith('Can'):
message = message.content
request = message[8:]
print(request)
if request.startswith('start'):
await channel.send('idk how')
what's the problem and how can i fix it?
Upvotes: 0
Views: 579
Reputation: 11
You need to put await client.process_commands(message)
in the end
Upvotes: 0
Reputation: 1097
I believe (but cannot test, as I do not have an discord bot to test on) that you cannot redefine on_message inside itself and update the client on_message handler. You can try the following instead, which does not declare a new on_message function:
import discord
client = discord.Client()
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.author.id == bot 1 id:
if message.content.startswith('<@!bot 2 id>'):
starterChannel = client.get_channel('private channel')
channel = message.channel
if channel == starterChannel:
await channel.send('ye')
if message.content.startswith('Can'):
channel = message.channel
message = message.content
request = message[8:]
print(request)
if request.startswith('start'):
await channel.send('idk how')
Upvotes: 1