discordjs我的机器人在本地运行但不能在heroku上正确运行

时间:2020-06-03 02:43:46

标签: discord.js

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

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“ node。”在本地运行我的机器人时,此代码工作得很好,但是通常我使用heroku运行我的机器人,因此它可以全时运行。问题是当我使用heroku运行此代码时,回复消息不会被删除。这不太好,好像有人试图在我的公告频道中运行命令,该命令将被删除,但漫游器的回复消息不会被发送,每个人都可以看到“您无法在此频道中发送命令!在<#707068673399399193670>频道。”在公告中。除此以外,我所有其他代码都可以与heroku完美配合。我觉得这可能是heroku的问题,但有什么建议吗?

1 个答案:

答案 0 :(得分:0)

不,这不是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 }));
    }
});