我在制作不和谐机器人时遇到问题

I am having problem in making a discord bot

这是我的代码。 @client.command() 被忽略。如果可以,请你帮助我。 @client.event 工作正常,但 @client.command() 完全被忽略了。即使我添加一个新命令或更改当前命令,它也不起作用。我什至没有收到任何错误。

import discord
import os
import random
from keep_alive import keep_alive
from discord.ext import commands

paint=[0xff0000 , 0x0000ff , 0x000000 , 0x00ffff , 0xffffff , 0xffd700 , 0x4b0082]
heads_tails = 'Heads', 'Tails'
prefix = ['-']
client = commands.Bot(prefix)
client.remove_command('help')

@client.event
async def on_ready():
    await client.change_presence(activity=discord.Game('with The Boys'))
    print("Ready to help you.")


@client.event
async def on_message(message):
    if message.content.startswith('-help'):
      embedVar = discord.Embed(
            title="Help arrived!",
            description="Here are a list of commands for your help",
            colour=(random.choice(paint)))
      embedVar.add_field(name="Bot Prefix",
                           value="-", inline=False)
      embedVar.add_field(name="Moderation Commands",
                           value="-help",
                           inline=True)
      embedVar.add_field(name="Fun commands", value="-coinflip", inline=True)
      embedVar.set_thumbnail(
            url=      "https://media.discordapp.net/attachments/923531605660815373/974248483479494686/charizard-mega-charizard-y.gif"
        )
      await message.channel.send(embed=embedVar)
    if message.content.startswith('-coinflip'):
        embedVar = discord.Embed(
            title="Coinflip",
            description=(f'You got {random.choice(heads_tails)}'),
            colour=(random.choice(paint)))
        await message.channel.send(embed=embedVar)
        await client.process_commands(message)

@client.command(pass_context = True)
async def mute(ctx, member: discord.Member):
     if ctx.message.author.server_permissions.administrator:
        role = discord.utils.get(member.server.roles, name='Muted')
        await ctx.add_roles(member, role)
        embed=discord.Embed(title="User Muted!", description="**{0}** was muted by **{1}**!".format(member, ctx.message.author), color=0xff00f6)
        await ctx.send(embed=embed)
     else:
        embed=discord.Embed(title="Permission Denied.", description="You don't have permission to use this command.", color=0xff00f6)
        await ctx.send(embed=embed)

keep_alive()
client.run(os.getenv('Token'))

尝试 运行 通过 shell。 我在 运行 使用简单的机器人时遇到了同样的问题,得到代码 0 作为输出但没有输出,

您面临的问题是您不小心将 client.process_commands(message) 函数放在了 coinflip 条件中。将这行代码移到 if 语句之外应该可以解决您的问题。

@client.event
async def on_message(message):
    await client.process_commands(message)

首先,您为什么不将“help”和“coinflip”设为机器人命令?使一切成为可能的机器人命令,而不是 async def on_message(message)

@client.command()
async def help(ctx)
     embed = discord.Embed(
            title="Help arrived!",
            description="Here are a list of commands for your help",
            colour=(random.choice(paint)))
      embedVar.add_field(name="Bot Prefix",
                           value="-", inline=False)
      embedVar.add_field(name="Moderation Commands",
                           value="-help",
                           inline=True)
      embedVar.add_field(name="Fun commands", value="-coinflip", inline=True)
      embedVar.set_thumbnail(
            url=      "https://media.discordapp.net/attachments/923531605660815373/974248483479494686/charizard-mega-charizard-y.gif"
        )
      await message.channel.send(embed=embed)