【问题标题】:Trying to figure out why my bot wont send an embed to the channel试图弄清楚为什么我的机器人不会向频道发送嵌入
【发布时间】:2020-08-26 12:44:00
【问题描述】:

我制作了一个通过 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

【问题讨论】:

  • 您要将嵌入发送到哪里?
  • 发出命令的同一频道

标签: python discord.py


【解决方案1】:
  1. 您还需要在函数中添加channel 参数。
  2. 您应该传递 message.channel 而不是 channel
  3. on_messageif语句中缩进start函数。

功能编辑:

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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-19
    • 1970-01-01
    • 2021-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-28
    相关资源
    最近更新 更多