命令引发异常:属性错误:'str'对象没有属性'send'



我试图做一个自定义嵌入命令,我得到了这个错误。

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'str' object has no attribute 'send'

这是我的代码:

@client.command()
@commands.has_permissions(administrator=True)
async def embed(self, ctx,*, msg=None):
if msg == None:
await ctx.send("No Message has been provided.  Please write your message within 30secs.")
def check(message):
return message.author == ctx.author and message.channel == ctx.channel
try:
mes=await self.client.wait_for('message',check=check,timeout=30.0)
except asyncio.TimeoutError:
await ctx.send('Timeout! Please be quicker next time.')
else:
msg=mes.content
em=discord.Embed(
description=msg,
timestamp=datetime.utcnow(),
color=discord.Color.random()).set_author(
name=f'{ctx.author.name}#{ctx.author.discriminator}',
icon_url=f'{ctx.author.avatar_url}')
await ctx.send(embed=em)

如果你可以修补它,请在下面告诉我:(

你在做

@client.command()
@commands.has_permissions(administrator=True)
async def embed(self, ctx,*, msg=None):

如果你在一个齿轮上,你需要做@commands.command。当做client.command装饰器虽然,你添加回调本身(它不是从类调用)。实际上下文传递给self,ctx成为您的第一个参数(字符串),而另一个参数msg只是保持为None

如果你在一个齿轮上,那么把它改成一个正常的命令。

@commands.command()
@commands.has_permissions(administrator=True)
async def embed(self, ctx,*, msg=None):
@testy.command(name='d')
@commands.has_permissions(administrator=True)
async def embed(ctx, msg=None):
if msg == None:
await ctx.send("No Message has been provided.  Please write your message within 30secs.")
def check(message):
return message.author == ctx.author and message.channel == ctx.channel
try:
mes=await testy.wait_for('message',check=check,timeout=30.0)
except asyncio.TimeoutError:
await ctx.send('Timeout! Please be quicker next time.')
else:
msg=mes.content
em=discord.Embed(description=msg, timestamp=datetime.datetime.utcnow(), color=discord.Color.random())
em.set_author(name=ctx.author, icon_url=ctx.author.avatar)
await ctx.send(embed=em)

使用你的代码为基础,我调整了一些事情,并验证它在我的测试机器人上工作。你可以看到我的bot的名字是"testy"所以你要用你的客户来代替他。使用命令'd'调用该命令,然后提示用户输入文本字符串。然后,该字符串与时间戳、用户的不和谐音名称和头像一起显示在嵌入中。希望这篇文章能给你指明正确的方向。

我不知道你在传递什么ctx,但它看起来像你在传递一个字符串的ctx基于错误,在这种情况下,没有发送()函数的字符串对象