当我的 Discord 机器人向已阻止它的用户发送消息时,如何阻止它崩溃?不和谐.js

问题描述 投票:0回答:1

所以我不知道是否需要为此提供代码,所以我不会。

基本上我和一个朋友正在试验我的机器人。有一次,我阻止了它,并要求我的朋友使用一个命令,让机器人向我发送消息。他们这样做了,机器人崩溃了。我绝对认为人们会阻止这个机器人;它可能会很烦人,那么当它尝试向已阻止它的用户发送 DM 时,如何防止它崩溃?

discord discord.js bots
1个回答
0
投票

一个简单的 try catch 很可能就足够了。

try {
    await command.execute(interaction);
} catch (error) {
    console.error(error);
    if (interaction.replied || interaction.deferred) {
        await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
    } else {
        await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
    }
}

查看discord.js 文档,了解如何防止此类事情发生。

© www.soinside.com 2019 - 2024. All rights reserved.