【问题标题】:(Discord.js v12) Mention Arguments?(Discord.js v12)提及参数?
【发布时间】:2021-04-26 19:14:43
【问题描述】:

我尝试使用参数和提及来创建命令。我所做的是,我想提一下文本通道作为论据。 我可能解释得不太好

这是示例

例如,我添加了语法为:<prefix> <message> <#channel> 的命令,但我不能在参数 [2] 中提及频道。

我尝试了什么:

let msg = args[1];
let channel = message.mentions.channels.first(args[2]); // It quite not make any sense, right?

message.channel.send(`Message: ${msg} \nIn channel: ${channel}!`);

它只是崩溃了。这里有一点帮助!

【问题讨论】:

    标签: discord.js


    【解决方案1】:

    它崩溃的原因是因为你使用了“args[]”错误,对于let msg = args[1];它应该设置为args[0]。现在对于频道,您可以使用args[1]

    您可以尝试使用message.mentions 所以您可以执行以下操作:

    let channel = message.mentions.channels.first();
    

    完整代码:

    let msg = args[0]; //Get the first word from the message
    let announceChannel = message.mentions.channels.first(); //Get the announcement channel
    message.channel.send(`Message: ${msg} \nIn channel: ${announceChannel}!`); //Let the sender know the announcement has been sent
    announcementChannel.send(msg); //Send the announcement
    

    【讨论】:

    • 有用,我试试看。
    • @JediThePro 运气好吗?这应该是解决方案。
    猜你喜欢
    • 2021-04-19
    • 2020-10-08
    • 1970-01-01
    • 2020-10-19
    • 2021-08-04
    • 2021-11-24
    • 2021-03-26
    • 2021-09-22
    • 2021-01-05
    相关资源
    最近更新 更多