Python 正在努力解决如何使用Discord.py将嵌入式消息发送到特定频道的问题

Python 正在努力解决如何使用Discord.py将嵌入式消息发送到特定频道的问题,python,python-3.x,discord,discord.py,Python,Python 3.x,Discord,Discord.py,我正在尝试创建一个建议命令,它在其中发送一个包含用户建议的嵌入,从而创建一个建议频道。但是我不断地犯错误。它发送确认消息,但随后在控制台中引发此错误: 忽略on_命令中的异常\u错误 回溯(最近一次呼叫最后一次): 文件“/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py”,第85行,包装 ret=等待coro(*args,**kwargs) 文件“main.py”,第473行,在建议

我正在尝试创建一个建议命令,它在其中发送一个包含用户建议的嵌入,从而创建一个建议频道。但是我不断地犯错误。它发送确认消息,但随后在控制台中引发此错误:

忽略on_命令中的异常\u错误
回溯(最近一次呼叫最后一次):
文件“/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py”,第85行,包装
ret=等待coro(*args,**kwargs)
文件“main.py”,第473行,在建议中
等待message.channel.send(“谢谢,您的建议已被跟踪!”)
AttributeError:“str”对象没有属性“channel”
上述异常是以下异常的直接原因:
回溯(最近一次呼叫最后一次):
文件“/opt/virtualenvs/python3/lib/python3.8/site packages/discord/client.py”,第343行,在运行事件中
等待coro(*args,**kwargs)
文件“main.py”,第72行,on_命令_错误
提出错误
文件“/opt/virtualenvs/python3/lib/python3.8/site packages/discord/ext/commands/bot.py”,第939行,在invoke中
等待ctx.command.invoke(ctx)
文件“/opt/virtualenvs/python3/lib/python3.8/site packages/discord/ext/commands/core.py”,第863行,在invoke中
等待注入(*ctx.args,**ctx.kwargs)
文件“/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py”,第94行,包装
从exc引发CommandInvokeError(exc)
discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:“str”对象没有属性“channel”
这是我的代码:

@client.command()
异步定义建议(ctx,*,消息):
等待message.channel.send(“谢谢,您的建议已被跟踪!”)
channel=client.get_channel(“849311393269284954”)
embedVar=discord.Embed(title=“New suggestion!”,description=f“{message}`.”格式(message),颜色=0x27db91)
embedVar.set_footer(text=“提交人:{}”。格式(message.author.display_name),icon_url=message.author.avatar_url)
等待channel.send(嵌入=embedVar)
谢谢你的帮助!:D

@client.command()
不同于消息上的
事件

on_message
有一个
discord.message
对象,它有很多属性。(
频道、作者、行会、内容等

当您执行
message.channel.send
时,您将有一个
discord.message
对象作为具有属性channel的message变量,因此
message.channel
获取
discord.TextChannel
对象,然后将消息发送到该对象

消息
在您的参数中,它变成了一个
字符串(str)
输入,而
不是
一个
discord.message
对象,但是您有
上下文(ctx)
,它也有类似的属性,但比消息有更多的属性。您只需使用
ctx.send(“您的邮件”)

修改后的代码如下所示:

@client.command()
async def suggest(ctx, *,message):
  await ctx.send("Thank you, your suggestion has been tracked in <#849311393269284954>!")


  channel = client.get_channel("849311393269284954") #this is an issue! Read more to find out

  embedVar = discord.Embed(title="New suggestion!", description=f"`{message}`", color=0x27db91) # why both f-string and .format()????? doesn't make sense
  embedVar.set_footer(text="Submitted by: {}".format(ctx.author.display_name), icon_url=ctx.author.avatar_url)

  await channel.send(embed=embedVar)

啊,行了!感谢您的帮助,虽然页脚没有,但会抛出以下错误:
embedVar.set\u footer(text=“Submitted by:{}”.format(ctx.author.display\u name),icon\u url=message.author.avatar\u url)AttributeError:'str'对象没有属性'author'
,但现在我不介意。它的主要部分工作得很好!:是我,我忘了将
消息.author.avatar\u url
更改为
ctx.author.avatar\u url
我知道了,我会试试看。是的,它起作用了D再次感谢。
@client.command()
async def suggest(ctx, *,message):
  await ctx.send("Thank you, your suggestion has been tracked in <#849311393269284954>!")


  channel = client.get_channel(849311393269284954) #removed the " "

  embedVar = discord.Embed(title="New suggestion!", description=f"`{message}`", color=0x27db91) # why both f-string and .format()????? doesn't make sense
  embedVar.set_footer(text="Submitted by: {}".format(ctx.author.display_name), icon_url=message.author.avatar_url)

  await channel.send(embed=embedVar)