Discord.py @client.commands() 无法执行但@client.events 可以执行

Discord.py @client.commands() unable to execute but @client.events can execute

出于乐趣为电子游戏 VALORANT 制作机器人时,我意识到我根本无法让 client.commands 工作,而 on_message 的 client.event 仍然可以工作

我其实不知道哪里出了问题

我尝试做的事情:

到目前为止没有任何效果,我是否在基本层面上遗漏了什么?

import discord
import random

from discord.ext import commands

client = commands.Bot(command_prefix=['v:'])

@client.event
async def on_ready():
    await client.change_presence(activity = discord.Game(name = "VALORANT"))
    print("Initiated!")

# commands that cannot work
@client.command()
async def ping(ctx):
    print("if this shows up then it works lmao")
    await ctx.send(f"Pong! {round(client.latency * 1000)}ms")

@client.command(aliases = ['RAgent', 'ragent', 'RandomAgent', 'randomagent'])
async def Random_Agent_Selection(ctx):
    print("if this shows up then it works lmao")
    Agents = ['Breach',
              'Brimstone',
              'Cypher',
              'Jett',
              'Killjoy',
              'Omen',
              'Phoenix',
              'Raze',
              'Reyna',
              'Sage',
              'Skye',
              'Sova',
              'Viper']
    await ctx.channel.send(f"Random Agent: {random.choice(Agents)}")

# event that DOES work
@client.event
async def on_message(message):
    if "valorant" in message.content.lower() and message.author.id != 750663559695958016: 
    #id = bot id so it wont infitely loop the command
        channel = message.channel
        await channel.send("The Valorant corporation is waiting for you")

client.run("TOKEN")

on_message 活动结束时您需要 process_commands

阅读更多:Here

修改后的代码如下:

@client.event
async def on_message(message):
    if "valorant" in message.content.lower() and message.author.id != 750663559695958016: 
    #id = bot id so it wont infitely loop the command
        channel = message.channel
        await channel.send("The Valorant corporation is waiting for you")
    await client.process_commands(message)