【问题标题】:discord bot command import text from text filediscord bot 命令从文本文件中导入文本
【发布时间】:2020-12-23 21:09:33
【问题描述】:

我想通过命令在我的 Discord Bot 中实现该功能,以便根据命令发送。更改日志中的信息/更新位于同一文件夹中的 .txt 文件中。 如何获取要发送的文件中的文本?

【问题讨论】:

  • python 的内置文件 I/O 工具 (open()) 不工作吗?你能分享一下你到目前为止写的代码的相关部分吗?

标签: python command discord


【解决方案1】:

示例代码我认为这就是你的意思

client = commands.Bot('!')

@client.command
async def command(ctx):
    open_file_ = open('file.txt', 'r')
    await ctx.send(open_file_.read())

这是你想要的吗?

【讨论】:

  • 你知道我如何用同样的命令运行这个文件(ghost.vbs)
  • 不抱歉,我知道如何通过 python 运行 vbs 文件。如果您知道代码,只需将其添加到命令中即可运行该文件
  • os.system("xxxxx.vbs") f = open("tytytyt.txt", "r") time.sleep(0.05) file = f.read() array = file.split ('\n') 等待 ctx.send (文件)
猜你喜欢
  • 2020-08-21
  • 1970-01-01
  • 1970-01-01
  • 2021-06-19
  • 2018-11-21
  • 2015-07-20
  • 2019-02-12
  • 2021-08-10
  • 1970-01-01
相关资源
最近更新 更多