Answer the question
In order to leave comments, you need to log in
How to solve discord.py error?
print('Loading...')
import discord, asyncio, config, os
from discord.ext import commands
from discord.ext.commands import Bot
prefix = config.prefix
bot = commands.Bot(command_prefix = prefix)
@bot.event
async def on_ready():
os.system('cls')
print('Complete!\n')
async def on_message(message):
print('{0.author}\n {0.content}\n'.format(message))
@bot.command()
async def say(message):
args = message.content
await message.channel.send(args.lstrip('{}say'.format(prefix)))
bot.run(Мой токен)
Ignoring exception in command say:
Traceback (most recent call last):
File "C:\Users\ \AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "D:\ \ \ \bot.py", line 19, in say
args = message.content
AttributeError: 'Context' object has no attribute 'content'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\ \AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\ \AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\core.py", line 859, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\ \AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Context' object has no attribute 'content'
Answer the question
In order to leave comments, you need to log in
The first argument to the command is not discord.Message
, but discord.Context
: https://discordpy.readthedocs.io/en/stable/ext/com... "
A command must always have at least one parameter, ctx, which is the Context as the first one.
@bot.command()
async def say(ctx: commands.Context):
args = ctx.message.content
await ctx.send(args.lstrip('{}say'.format(prefix)))
@bot.command()
async def say(ctx: commands.Context, *, content: str):
await ctx.send(content)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question