0

When I try to combine a command and an event only one of them works while the other doesn't.

import discord
import random
from discord.ext import commands

client = commands.Bot(command_prefix='.')

@client.event
async def on_ready():
    print('I am ready.Let us begin')

@client.command(aliases=['8ball'])
async def _8ball(ctx, *, question):
    responses = ['Razsamaha.',
                 'Profesor Iks',
                 'Jen Grei',
                 'Shelma']
    await ctx.send(f'Question: {question}\nAnswer:{random.choice(responses)}')

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('hello'):
        await message.channel.send('Hello!')

client.run('')

The first @client.event works in both cases, whether only with the 8ball command or the hello event. The issue is that when I try to run them both (the 8ball command and the hello event) together, only the one of them works, yet on their own, they both work okay. Where am I messing up? I only just installed python today.

Pudge
  • 103
  • 1
  • 10
  • You need `await client.process_commands(message)` in your `on_message` event for commands to work. Can you update your code to show how you are using it? – Benjin Apr 07 '20 at 07:17
  • it works when I edit it so: ``` client.event async def on_message(message): if message.author == client.user: return if message.content.startswith('hello'): await message.channel.send('Hello!') wait client.process_commands(message) ``` ``` – Pudge Apr 07 '20 at 07:40

0 Answers0