NameBulist
NameBulist

Reputation: 35

discord.py Why @client.command dont work?

Nothing happens when i run the register command. I have already tried everything, but nothing helps( 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')
    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)

Upvotes: 2

Views: 963

Answers (3)

boredscripter
boredscripter

Reputation: 108

The answer above is incorrect - yes the reasoning is correct BUT remember: Python is CAPS SENSITIVE.

The error you have made is very simple I couldn't even notice it.

What you have to do is:

@client.command()

Now, you may say there is no difference between the answer above and the answer I have written here, BUT if you watch carefully, in the answer above me there was a Capital letter C.

Be. Careful. On. Capital. Letters.

Also, name and description are optional inside of the parenthesis.

If you need more help please DM me (officer grr#6609)

Upvotes: 0

rupam_das
rupam_das

Reputation: 60

Actually, it is not

@client.command

The correct way to use it is..

@client.command(name="Command name", description="Command Description")

The 'name' and 'description' arguments are optional..

Another thing... Since you use the 'on_message' event.. Do this...

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)

Your whole code according to me:

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)

Upvotes: 2

Bhavyadeep Yadav
Bhavyadeep Yadav

Reputation: 831

I am pretty sure I know the answer. You are using:

@Client.command

Here is the error:

You are supposed to use parenthesis after command, i.e., you should use:

@Client.command()

I think this would work. If this doesn't work tell me so that I would check it again.

Thank You!

Upvotes: 1

Related Questions