【问题标题】:How to send a file/attachment interactions.py如何发送文件/附件 interactions.py
【发布时间】:2022-11-28 08:07:36
【问题描述】:

我正在尝试使用 interactions.py 库和代码将文件发送到不和谐

async def scatter(ctx: interactions.CommandContext, area: str):
    N = 50
    x = np.random.rand(N)
    y = np.random.rand(N)
    colors = np.random.rand(N)
    area = (30 * np.random.rand(N)) ** 2
    plt.scatter(x, y, s=area, c=colors, alpha=0.5)
    plt.savefig('scatter.png')
    plt.close()
    message = await ctx.send('loading img')
    await ctx.channel.send(attachments=[discord.Attachment("scatter.png")])
    os.remove('scatter.png')

我得到错误

Task exception was never retrieved
future: <Task finished name='Task-16' coro=<scatter() done, defined at C:\Users\Owner\AppData\Local\Programs\Python\Python38\lib\site-packages\interactions\client\models\command.py:901> exception=TypeError('__init__() takes 1 positional argument but 2 were given')>
Traceback (most recent call last):
  File "C:\Users\Owner\AppData\Local\Programs\Python\Python38\lib\site-packages\interactions\client\models\command.py", line 920, in wrapper
    raise e
  File "C:\Users\Owner\AppData\Local\Programs\Python\Python38\lib\site-packages\interactions\client\models\command.py", line 906, in wrapper
    return await coro(ctx, *args, **kwargs)
  File "D:/Users/Owner/PycharmProjects/Matplotlib-discord/main.py", line 38, in scatter
    await ctx.channel.send(attachments=[discord.Attachment("scatter.png")])
TypeError: __init__() takes 1 positional argument but 2 were given

我该怎么做才能使附件正常工作并发送文件?

【问题讨论】:

    标签: python discord


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-22
      • 1970-01-01
      • 2013-09-04
      • 1970-01-01
      • 1970-01-01
      • 2020-01-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多