我制作了一个脚本,该脚本通过webhook发送嵌入,它工作正常,但是我试图将其转换为通过bot发送到同一频道。我似乎无法弄清楚(我以前从未使用过该机器人发送嵌入代码。)
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
答案 0 :(得分:1)
channel
参数。message.channel
而不是channel
。start
的{{1}}语句中缩进if
函数。功能编辑:
on_message
on_message编辑:
async def start(keyword, channel):
#Code
await embeded(channel)