-1

I am trying to create a Discord bot and add some commands to it but it seems to not work. I added the print statement to figure out if the command was added, but it returns None. Calling "!hello" in the Discord channel raises CommandNotFound.

import discord
from discord.ext import commands

client = commands.Bot(command_prefix="!")
TOKEN = [some token]


@client.command
async def hello(ctx, arg):
    await ctx.channel.send(arg)

print(client.get_command("hello"))

client.run(TOKEN)

2 Answers 2

4

That's because you are missing parentheses after @client.command, just add () to it like this:

@client.command()
Sign up to request clarification or add additional context in comments.

Comments

2

ctx.channel.send() needs to be replaced by ctx.send() and as loloToster just said, @client.command needs () behind it so the final code would be:

from discord.ext import commands

client = commands.Bot(command_prefix="!")
TOKEN = [some token]


@client.command()
async def hello(ctx, arg):
    await ctx.send(arg)

print(client.get_command("hello"))

client.run(TOKEN)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.