Python discord.py为什么@client.command不起作用?

Python discord.py为什么@client.command不起作用?,python,python-3.x,discord.py,bots,Python,Python 3.x,Discord.py,Bots,当我运行register命令时,不会发生任何事情。我已经试过了所有的方法,但都没用( 进口不和 进口环境 从discord.ext导入命令 intents = discord.Intents.all() client = commands.Bot(command_prefix='!', intents=discord.Intents.all()) TOKEN = env.discord_token("DISCORD_TOKEN") @client.event async

当我运行register命令时,不会发生任何事情。我已经试过了所有的方法,但都没用( 进口不和 进口环境 从discord.ext导入命令

intents = discord.Intents.all()
client = commands.Bot(command_prefix='!', intents=discord.Intents.all())

TOKEN = env.discord_token("DISCORD_TOKEN")


@client.event
async def on_ready():
    print("Im ready to go : {0.user}".format(client))

@client.event
async def on_message(message):

    if message.author == client.user:
        return
    if message.content.startswith("!instagram"):
        await message.channel.send('https://www.instagram.com')
    if message.content.startswith("!youtube"):
        await message.channel.send("https://www.youtube.com/channel/fsaf!212faf")

#Dont work
@client.command
async def register(ctx, arg1, arg2):
    await ctx.send(arg2, arg1)



@client.event
async def on_member_join(member):
    role_1 = member.guild.get_role(807733964214321878)
    await member.add_roles(role_1)

client.run(TOKEN)

我很确定我知道答案。您正在使用:

@Client.command
以下是错误: 您应该在
命令
之后使用括号,即。, 你应使用:

@Client.command()
我想这样行得通。如果不行,请告诉我,以便我再次检查

谢谢!

事实上,它不是

@client.command
正确的使用方法是

@client.command(name="Command name", description="Command Description")
“name”和“description”参数是可选的

还有一件事。。。 因为您使用了“on_message”事件。。 做这个

async def on_message(message):

    if message.author == client.user:
    return
    if message.content.startswith("!instagram"):
        await message.channel.send('https://www.instagram.com')
    if message.content.startswith("!youtube"):
        await message.channel.send("https://www.youtube.com/channel/fsaf!212faf")

    else:
        await client.process_commands(message)
根据我的说法,你的全部代码:

import discord 
import env 
from discord.ext import commands

intents = discord.Intents.all()
client = commands.Bot(command_prefix='!', intents=discord.Intents.all())

TOKEN = env.discord_token("DISCORD_TOKEN")


@client.event
async def on_ready():
    print("Im ready to go : {0.user}".format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
       return
    if message.content.startswith("!instagram"):
        await message.channel.send('https://www.instagram.com')
    elif message.content.startswith("!youtube"):
        await message.channel.send("https://www.youtube.com/channel/fsaf!212faf")
    else:
        await client.process_commands(message)


@client.command(name='reg')
async def register(ctx, arg1, arg2):
    await ctx.send(arg2, arg1)



@client.event
async def on_member_join(member):
    role_1 = member.guild.get_role(807733964214321878)
    await member.add_roles(role_1)

client.run(TOKEN)

上面的答案是不正确的-是的,推理是正确的,但请记住:Python是敏感的

你犯的错误很简单,我甚至没注意到

你要做的是:

@client.command()
现在,你可能会说上面的答案和我在这里写的答案没有区别,但是如果你仔细观察,在我上面的答案中有一个大写字母C

小心点,大写字母

此外,名称和说明在括号内是可选的


如果您需要更多帮助,请与我联系(grr#6609警官)

谢谢您的回答,但没有帮助(仍然不起作用(再次检查答案…据我所知,我已对其进行了编辑,这需要将其添加到def on消息的末尾,然后输出以下内容:忽略命令中的异常无:discord.ext.commands.errors.CommandNotFound:command“reg”是的,我试过这样做:bot.add_command(reg),但没有任何改变。你能用你自己的开发来修复我的代码吗?在我看来,我在这个问题上太笨了。你是如何“运行”的命令?你认为这样做会发生什么?我用私人消息“!reg”和参数给机器人写信,它应该把参数返回给我,但它什么都不做什么用大写字母,用小写字母。没有name@client.command必须始终使用小写