【问题标题】:How to split a defined string in discord.js如何在 discord.js 中拆分定义的字符串
【发布时间】:2021-08-17 07:08:14
【问题描述】:

我正在使用 replit 数据库制作排行榜命令,就像我已经为具有其 id 的用户存储数据一样,现在我想转换该 id 以提及这里是我的代码:

db.list().then(keys => {
    const eachline = keys.split('/n')
    for (const line of eachline) {
      if(line.includes('Donation:')) {
        const splat = line.split('Donation:')[1]
        const final = '<@'+splat+'>';
        message.chanel.send(final);
      }}
  });

这是我可以从db.list() 得到的 但我在const eachline = keys.split('/n') 部分遇到错误,错误是TypeError: keys.split is not a function

【问题讨论】:

    标签: javascript node.js database discord discord.js


    【解决方案1】:

    显然keys 不是字符串,所以你需要弄清楚它是什么

    db.list().then(keys => {
        console.log(keys);
    });
    

    我会从图像中假设它是一个字符串数组?在这种情况下,您可能可以这样做:

    db.list().then(lines => {
        for (const line of lines) {
            if(line.includes('Donation:')) {
                const splat = line.split('Donation:')[1]
                const final = '<@'+splat+'>';
                message.chanel.send(final);
            }
        }
    });
    

    【讨论】:

    • 谢谢!它有效?也是它的频道而不是频道?
    • 他们是否要一次发送所有提及?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-03
    • 1970-01-01
    • 1970-01-01
    • 2021-07-20
    • 1970-01-01
    相关资源
    最近更新 更多