简体   繁体   中英

Why is my bot.command function in discord.py not working?

I have tried looking around the inte.net for answers but I'm not finding anything that fixes my problem:

import os
import asyncio

import discord
from discord.ext import commands

token = "here is my token"

bot = discord.Client()

bot = commands.Bot(command_prefix='!')

@bot.command()
async def length(ctx):
    await ctx.send('your message is {} characters long.'.format(len(ctx.message.content)))
    print("test print")

bot.run(token)

The length function does not work at all, and its not printing test print in the console.

Does anyone know what the problem is? there are a few other bot.xxx functions in there that works.

It does not work because you have double bot. Your should only have bot = commands.Bot(command_prefix='!')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM