【问题标题】:discordjs my bot runs correctly when running locally but not with herokudiscordjs 我的机器人在本地运行时正常运行,但在 heroku 上运行不正常
【发布时间】:2020-09-21 15:37:44
【问题描述】:

因此,如果有人尝试在某个频道中运行命令,我的机器人将(或应该)删除该命令并告诉用户不要在该频道中运行命令,这是我的代码:

bot.on('message', msg=>{
    if(msg.channel.type === 'dm' || msg.author.id === bot.user.id || msg.author.id === '706663416697192489'){
    return;
    }
    else if(msg.content.startsWith("!") && msg.channel.id === '706662574606778490'){
    msg.delete()
    msg.reply('you can\'t send commands in this channel! Send commands in the <#707068673399193670> channel.').then(function(msg){
    msg.delete({timeout: 2000})
    })
    }
});

当我使用 ctrl+c "n​​ode ." 在本地运行我的机器人时,此代码工作得非常好,但通常我使用 heroku 运行我的机器人,因此它可以全时运行。问题是当我使用 heroku 运行此代码时,回复消息不会被删除。这不太好,好像有人试图在我的公告频道中运行命令,该命令将被删除,但机器人的回复消息不会,每个人都可以看到“你不能在这个频道发送命令!发送命令在 频道。”在公告中。除了这个,我所有的其他代码都可以与 heroku 完美配合。我觉得这可能是 heroku 的一个问题,但有什么建议吗?

【问题讨论】:

    标签: discord.js


    【解决方案1】:

    不,这不是heroku的错,你有重复的变量名

    bot.on('message', msg => {
        if (msg.channel.type === 'dm' || msg.author.id === bot.user.id || msg.author.id === '706663416697192489') return;
        if (msg.content.startsWith("!") && msg.channel.id === '706662574606778490') {
            msg.delete();
            msg.reply('you can\'t send commands in this channel! Send commands in the <#707068673399193670> channel.')
                .then(reply => reply.delete({ timeout: 2000 }));
        }
    });
    

    【讨论】:

    • 没问题,我看过一些帖子,您承认答案,但您不接受。你是新来的,所以没关系,但你应该开始接受它们,所以如果将来人们偶然发现它,他们可以立即找到它,或者他们认为这不是问题并尝试给出另一个解决方案。
    • 我如何承认答案
    猜你喜欢
    • 1970-01-01
    • 2021-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-26
    • 1970-01-01
    • 2020-09-16
    • 2013-04-02
    相关资源
    最近更新 更多