ffabrice
ffabrice

Reputation: 17

Discord Bot - Python

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)

Upvotes: -1

Views: 289

Answers (2)

NikkieDev
NikkieDev

Reputation: 209

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)

Upvotes: 2

loloToster
loloToster

Reputation: 1413

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

@client.command()

Upvotes: 4

Related Questions