【问题标题】:Discord.js: How to send contents of a .txt file in a message?Discord.js:如何在消息中发送 .txt 文件的内容?
【发布时间】:2021-04-22 17:10:36
【问题描述】:

所以我有一个包含一些信息的 .txt 文件,我想以某种方式在消息中发送它的内容。如何实现?

我试图想出可能的解决方案,但我不相信它们会奏效,我正在寻求您的帮助。

【问题讨论】:

    标签: discord.js


    【解决方案1】:

    首先,你需要定义fs

    const fs = require('fs'); //this is a package that reads files
    

    然后,您定义文本文件的位置和编码:

    var textFile = fs.readFileSync('./textFile.txt', {"encoding": "utf-8"})
    

    文本文件的内容将被读取,textFile var 将包含它们

    在消息中发送它的内容

    message.channel.send(textFile)
    

    【讨论】:

    • 哦,就是这么简单。谢谢你的帮助先生!
    • 完全没问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-26
    • 2021-10-17
    • 1970-01-01
    • 2022-08-04
    • 2021-09-08
    • 1970-01-01
    • 2021-04-01
    相关资源
    最近更新 更多