python - 试图弄清楚为什么我的机器人不会向频道发送嵌入
问题描述
我制作了一个通过 webhook 发送嵌入的脚本,它工作得很好,但我正在尝试将它转换为通过机器人发送到同一个频道。我似乎无法弄清楚(我以前从未使用过该机器人来发送嵌入。)
async def start(keyword):
SOME CODE HERE
await embeded(channel)
async def embeded(channel):
# Discord Embed Setup
embed = Embed(
description=f"[**eBay Link**]({eBayLink})",
color=0x0d0d22,
timestamp='now' # sets the timestamp to current time
)
embed.set_author(name=Titles)
embed.add_field(name='Average', value=Averages, inline=True)
embed.add_field(name='Lowest', value=Lowests, inline=True)
embed.add_field(name='Highest', value=Highests, inline=True)
embed.add_field(name='Margin', value=Margins, inline=True)
embed.add_field(name='Postage', value=Postages, inline=True)
embed.set_footer(text='TEST', icon_url='IMAGE')
embed.set_thumbnail(image.get_attribute('src'))
await channel.send(embed=embed)
print("Embed sent to discord!")
@client.event
async def on_ready():
print("Bot is online!")
@client.event
async def on_message(message):
if message.content.startswith('!flip '):
keyword = message.content.split('!flip ')[1]
await start(keyword, channel)
client.run(token)
我得到错误
await start(keyword, channel)
NameError: name 'channel' is not defined
解决方案
- 您还需要向函数添加
channel
参数。 - 你应该通过
message.channel
而不是channel
. - 语句中的缩进
start
函数。if
on_message
功能编辑:
async def start(keyword, channel):
#Code
await embeded(channel)
on_message 编辑:
@client.event
async def on_message(message):
if message.content.startswith('!flip '):
keyword = message.content.split('!flip ')[1]
await start(keyword, message.channel)
推荐阅读
- kubernetes - 如何在 Kubernetes 中删除处于 Unknown 状态的 Pod?
- sql - 优化大数据运行缓慢的sql查询
- actions-on-google - 在我的谷歌操作中添加支持的语言时出错
- shopify - Shopify 液体 如何隐藏缺货产品,直到点击集合页面上的元素?
- authentication - Symfony 4.2:防火墙配置不加载内存用户提供程序
- javascript - 使用array.prototype时如何访问数组
- android - Intent.setType() 对 android 的 Intent 选择器的影响
- python - PyQT GUI 与不同线程中的 SQLAlchemy 查询
- javascript - 将液体分配给javascript变量
- android - 获取场地时获取 403