ASCII表不格式,因为我想要

发布于 2025-01-22 17:03:25 字数 2047 浏览 2 评论 0原文

我正在使用MySQL进行Discord机器人,数据库存储了一些用户名和密码。我从MySQL中的表中获取数据以在ASCII表中格式化。预期的输出就像下面的图像一样。 (将其编辑看起来更好)

.------------------------------------------------.
|       Username       |        Password         |
|----------------------|-------------------------|
|      amonggers       |          no             |
|  no username for u   |          no             |
|  not even this one   |          no             |
|         no           |          no             |
'------------------------------------------------'

但是机器人形成了这样的桌子。

.------------------------------------------------.
|       Username       |        Password         |
|----------------------|-------------------------|
| amonggers            |          no 
 |
| no username for u    |          no
 |
| not even this one    |          no
 |
| no                   |          no             |
'------------------------------------------------'

编辑:我还将其记录下来,并且输出比Discord Bot One要好一些。

.------------------------------------------------.
|       Username       |        Password         |
|----------------------|-------------------------|
 |amonggers            |          no             
 |no username for u    |          no             
 |not even this one    |          no             
|         no           |          no             |
'------------------------------------------------'

[![Console Log创建] [3]] [3] 命令代码任何帮助,谢谢。

client.on("messageCreate", async (message) => {
    if (message.content.toLowerCase().startsWith("=list")) {
        connection.query("SELECT * FROM rbinfo", (err, results) => {
            if (err) {
                console.log(err)
            }
            const ascii = require('ascii-table');
            var table = new ascii()
            table.setHeading('Username', 'Password')
            results.forEach(ok => table.addRow(ok.Username, ok.Password))
        });
    }
});

这完全感谢

I'm making a discord bot using MySQL, the database stores some usernames and passwords. I fetch the data from the table in MySQL to format it in an ASCII table. The expected output was to be like the image below. (edited it to look better)

.------------------------------------------------.
|       Username       |        Password         |
|----------------------|-------------------------|
|      amonggers       |          no             |
|  no username for u   |          no             |
|  not even this one   |          no             |
|         no           |          no             |
'------------------------------------------------'

But the bot forms the table like this.

.------------------------------------------------.
|       Username       |        Password         |
|----------------------|-------------------------|
| amonggers            |          no 
 |
| no username for u    |          no
 |
| not even this one    |          no
 |
| no                   |          no             |
'------------------------------------------------'

Edit: I also console logged it and the output is a bit better than the discord bot one.

.------------------------------------------------.
|       Username       |        Password         |
|----------------------|-------------------------|
 |amonggers            |          no             
 |no username for u    |          no             
 |not even this one    |          no             
|         no           |          no             |
'------------------------------------------------'

[![Console Log created][3]][3]
Heres the command code

client.on("messageCreate", async (message) => {
    if (message.content.toLowerCase().startsWith("=list")) {
        connection.query("SELECT * FROM rbinfo", (err, results) => {
            if (err) {
                console.log(err)
            }
            const ascii = require('ascii-table');
            var table = new ascii()
            table.setHeading('Username', 'Password')
            results.forEach(ok => table.addRow(ok.Username, ok.Password))
        });
    }
});

Any help at all is appreciated, thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文