Javascript 用户名和参数正在连接?\\Discord.js

Javascript 用户名和参数正在连接?\\Discord.js,javascript,bots,discord,Javascript,Bots,Discord,[text]正在与[username]组合(您可以将任何用户名放置在“realdonaldtrump”所在的位置。之后的任何内容都是实际消息 我尝试了很多方法,唯一能做的就是让特朗普成为默认推文,但无法更改它,因此它将是>tweet[message]而不是>tweet[username][message],但我希望有自定义用户名。有没有关于如何从[text]中删除[username]的线索 这是代码 exports.exec = async (client, message, args, lev

[text]
正在与
[username]
组合(您可以将任何用户名放置在“
realdonaldtrump
”所在的位置。之后的任何内容都是实际消息

我尝试了很多方法,唯一能做的就是让特朗普成为默认推文,但无法更改它,因此它将是
>tweet[message]
而不是
>tweet[username][message]
,但我希望有自定义用户名。有没有关于如何从
[text]中删除
[username]
的线索

这是代码

exports.exec = async (client, message, args, level, settings, texts) => {

    const user = args[0];

    // Fires Error message that the command wasn't ran correctly.
    if (!user) {
        return client.emit('commandUsage', message, this.help);
    }
    // Fires Error message that the command wasn't ran correctly.

    const text = args.join(" ");

    // Below is a self-deletion message prior to image sending when it's fetching the actual image.
    message.channel.send({
        embed: {
            color: 0,
            description: `${message.author} Generating image.`
        }
    }).then(msg => {
        msg.delete(5000).catch(() => { });
    }).catch(e => {
    });
    // Above is a self-deletion message prior to image sending when it's fetching the actual image.

    try {
        const { body } = await snekfetch.get(`https://nekobot.xyz/api/imagegen?type=${user.toLowerCase() === "realdonaldtrump" ? "trumptweet" : "tweet"}&username=${user.startsWith("@") ? user.slice(1) : user}&text=${encodeURIComponent(text)}`);
        message.channel.send("", { file: body.message });

        // Below is a automatic logger
    } catch (err) {
        const errorlogs = client.channels.get('480735959944527886')
        const embed = new discord.RichEmbed()
            .setAuthor("ERROR", "https://i.imgur.com/Omg7uJV.png")
            .setDescription(`${message.author} An error has occured using this command, this has automatically be logged and sent to ${client.channels.get('480735959944527886')} to be reviewed.`)
            .setColor(0)
            .setTimestamp()
        message.channel.send({ embed });
        errorlogs.send(`Error with \`$tweet\` command!\n\nError:\n\n ${err}`)
    }
    // Above is a automatic logger
};

您正在连接
参数
以设置
文本
变量

const text = args.join(" ");
但在您的示例中,由于
args
值是
[“realdonaltrump”,“yeeet”]
,它导致
文本具有
值“realdonaltrump yeet”

只需按照对
用户
变量所做的操作:

const text = args[1]

您可能需要验证参数的值。

您可以使用
string.replace
方法,它会将用户名替换为空:

const text = args.join(" ").replace(new RegExp(`${user}`), "")

希望有帮助!!!

你能给我们看完整的代码吗?你正在使用wait,但是异步部分是什么?很抱歉,重新编辑了代码块,使除了导出选项之外的所有代码都能正常工作:)哇。我花了一个多小时盯着这个,在某个阶段我看到了
consttext=args[0]
。真不敢相信就这样。。多谢各位