【问题标题】:discord.js edit the message that send to user dmdiscord.js 编辑发送给用户 dm 的消息
【发布时间】:2021-11-09 13:39:09
【问题描述】:

我想编辑机器人在用户直接消息中发送的消息,但出现错误:

message.author.edit 不是函数

这是我的代码:

    if (message.content === "#مقابلة") {
        message.channel.send(eembed);   
        if (!(authorId in userApplications)) {
            userApplications[authorId] = { "step" : 1}
            
            
            message.author.send(embed1);
        }
  
    } else {
  
        if (message.channel.type === "dm" && authorId in userApplications) {
            let authorApplication = userApplications[authorId];
  
            if (authorApplication.step == 1 ) {
                authorApplication.answer1 = message.content;
                message.author.edit(embed2);
                authorApplication.step ++;

【问题讨论】:

    标签: discord discord.js bots


    【解决方案1】:

    TextChannel#send 方法返回一个带有标准<Message> 对象的承诺,你可以像这样调用Message.edit() 函数:

    
    if (message.content === "#مقابلة") {
        message.channel.send(eembed);
        if (!(authorId in userApplications)) {
            userApplications[authorId] = {
                "step": 1
            }
            message.author.send(embed1).then((editMessage) => {
    
                    if (message.channel.type === "dm" && authorId in userApplications) {
                        let authorApplication = userApplications[authorId];
    
                        if (authorApplication.step == 1) {
                            authorApplication.answer1 = message.content;
                            editMessage.edit(embed2);
                            authorApplication.step++;
                        });
                }
            }
        }
    
    

    【讨论】:

    • 如果我用 urs 和应用程序机器人替换我的代码,它不会向频道发送问题的答案
    • 你不需要替换它,抓住它的本质我发送的只是一个例子,无论如何用你的代码编辑我的答案
    猜你喜欢
    • 1970-01-01
    • 2021-08-02
    • 2020-11-28
    • 2021-04-02
    • 1970-01-01
    • 2018-09-25
    • 2015-03-03
    • 1970-01-01
    • 2018-05-27
    相关资源
    最近更新 更多