Discord.js机器人因权限错误而崩溃



我正在测试两台服务器,在一台服务器上,机器人程序可以工作,但在另一台服务器不工作。

然而,ping命令在中起作用

使机器人只在一台服务器上崩溃,而在另一台服务器上工作的命令

import { MessageActionRow, MessageButton, MessageEmbed } from 'discord.js';
export const data = {
name: 'ticket',
description: 'Makes a ticket',
};
const actionRow = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('create-ticket')
.setLabel('티켓 생성하기')
.setEmoji('🎟️')
.setStyle('PRIMARY'),
);
export async function onRun(interaction) {
const embed = new MessageEmbed()
.setColor('#0099ff')
.setTitle('티켓 생성')
.setDescription('어쩌고 저쩌고');
await interaction.channel.send({ embeds: [embed], components: [actionRow] });
}

这是工作于的ping命令

import { MessageEmbed } from 'discord.js';
import { client } from '../bot.js';
export const data = {
name: 'ping',
description: 'Ping Pong!',
};
export async function onRun(interaction) {
const message = await interaction.reply({ content: 'Pinging...', fetchReply: true });
const embed = new MessageEmbed()
.setTitle('Pong!')
.addField('Message Latency', `${(message.createdTimestamp || Date.parse(message.timestamp)) - interaction.createdTimestamp}ms`)
.addField('Discord Latency', `${client.ws.ping}ms`);
await interaction.editReply({ embeds: [embed], content: 'Pong!' });
}

编辑:错误Discord表示交互失败,机器人程序崩溃,出现以下日志

C:UsersissacWebstormProjectsdiscord-botnode_modulesdiscord.jssrcrestRequestHandler.js:350
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Missing Permissions
at RequestHandler.execute (C:UsersissacWebstormProjectsdiscord-botnode_modulesdiscord.jssrcrestRequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (C:UsersissacWebstormProjectsdiscord-botnode_modulesdiscord.jssrcrestRequestHandler.js:51:14)
at async TextChannel.send (C:UsersissacWebstormProjectsdiscord-botnode_modulesdiscord.jssrcstructuresinterfacesTextBasedChannel.js:175:15)
at async Module.onRun (file:///C:/Users/issac/WebstormProjects/discord-bot/src/commands/ticket.js:22:5) {
method: 'post',
path: '/channels/950311913391259659/messages',
code: 50013,
httpStatus: 403,
requestData: {
json: {
content: undefined,
tts: false,
nonce: undefined,
embeds: [
{
title: '티켓 생성',
type: 'rich',
description: '어쩌고 저쩌고',
url: null,
timestamp: 0,
color: 39423,
fields: [],
thumbnail: null,
image: null,
author: null,
footer: null
}
],
components: [ { components: [ [Object] ], type: 1 } ],
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined
},
files: []
}
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

这意味着您的机器人程序缺少在该服务器上发送消息的权限。您可以通过在发送以下消息后添加.catch语句来防止它崩溃:

const message = await interaction.reply({ content: 'Pinging...', fetchReply: true }).catch((e) => console.log(e))

问题是嵌入链接权限关闭

最新更新