简体   繁体   中英

How to split a defined string in discord.js

I am making a leaderboard command with replit database like I have stored data for users with their id and now I want to convert that ids to mention here's my code:

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() 得到的结果

This is what I can get from db.list() But I am getting an error on the part const eachline = keys.split('/n') the error is TypeError: keys.split is not a function

Well obviously keys isn't a string, so you need to figure out what it is

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

I'd assume from the image that it's an array of strings? In which case you can probably just do:

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);
        }
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM