如何创建一个通过文本文件并发送我需要的文本的命令?

How can I make a commmand that goes through a txt file and sends the text that i need?

我想在 discord 中制作一个 api 关键东西,但我不知道如何为 ex

一个一个地浏览 txt 文件
  1. 测试
  2. 测试2
  3. 测试3
  4. 测试4

如果第一个用户发送 !key 它会发送测试如果第二个用户发送 !key 它会发送 test2.And 依此类推。

这是我到目前为止所做的:

@bot.command()
async def key(ctx):
  f = open("keys.txt")
  keys = f.readlines()
  f.close()

  await ctx.send(keys)

但是我收到了如下错误:

Ignoring exception in command key:
Traceback (most recent call last):
  File "/home/runner/djopasjopdapjaopds/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "main.py", line 42, in key
    await ctx.send(keys)
  File "/home/runner/djopasjopdapjaopds/venv/lib/python3.8/site-packages/discord/abc.py", line 1065, in send
    data = await state.http.send_message(channel.id, content, tts=tts, embed=embed,
  File "/home/runner/djopasjopdapjaopds/venv/lib/python3.8/site-packages/discord/http.py", line 254, in request
    raise HTTPException(r, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In content: Must be 4000 or fewer in length.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/runner/djopasjopdapjaopds/venv/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/home/runner/djopasjopdapjaopds/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/home/runner/djopasjopdapjaopds/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body

键是这样的形式 Ux9wMkTXDtmrgdJfLSHvzF74jsA3qp uWSj76hBF9taRQG4VEnyJfbkmsLMPe BJ5fPsV9N8kbRqdpTcx2geHwCGFUDr 等等

我猜这...也许

with open("keys.txt") as f:
   keys = iter(f.readlines())
@bot.command()
async def key(ctx):
  await ctx.send(next(keys))