我无法运行任何命令discord.py

时间:2020-08-17 22:56:51

标签: python discord.py

因此,我一直在为不和谐创建一个机器人,因此我一直在关注许多教程,但是我的唯一命令无法运行。所以这是我的代码:

import discord
import os
from discord.ext import commands

client = discord.Client()
bot = commands.Bot(command_prefix = "_")

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    if message.content.startswith("salut le bot"):
        await message.channel.send("Salut, je suis Bapo Bot, pour vous servir !")
    if message.content.startswith("merci fréro"):
        await message.channel.send("De rien mon gars !")
    if str(message.channel) == "uniquement-des-images" and message.content != "":
        await message.channel.purge(limit=1)
        print('Message :', (message.content), 'from', (message.author), 'deleted successfully.')

@client.event
async def on_ready():
    print('Logged in as')
    print(client.user.name)
    print(client.user.id)
    print(discord.__version__)
    print('------------------')

@bot.command()
async def ping(ctx):
    await ctx.send('Pong!')

client.run(os.environ['BOT_TOKEN'])

此代码未给出任何错误。 起初,我以为client = discord.Client()是在创建错误,但是当我删除它时,整个漫游器不再起作用。我尝试更改bot前缀或更改现在称为bot的名称(我仍然是python中的菜鸟,所以我不称呼此名称),但现在遇到了麻烦。

1 个答案:

答案 0 :(得分:2)

您需要将await client.process_commands()添加到on_message事件中!

我本人将自己留在方法的底部!