为什么不能同时拥有@ client.event和@ client.command

时间:2020-04-06 22:43:03

标签: python python-3.x discord.py

当我尝试组合一个命令和一个事件时,只有其中一个起作用,而另一个则不起作用。

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('')

第一个@ client.event在两种情况下均有效,无论是仅使用8ball命令还是hello事件。问题是,当我尝试同时运行它们(8ball命令和hello事件)时,只有其中一个可以运行,但靠它们自己运行,它们都可以。我在哪里弄糟?我今天才刚安装python。

0 个答案:

没有答案