Discord.js 机器人因权限错误而崩溃
Discord.js bot crashes with permission error
我正在测试两台服务器,在一台服务器上,该机器人可以运行,但该机器人在另一台服务器上无法运行。
但是,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:\Users\issac\WebstormProjects\discord-bot\node_modules\discord.js\src\rest\RequestHandler.js:350
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Missing Permissions
at RequestHandler.execute (C:\Users\issac\WebstormProjects\discord-bot\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (C:\Users\issac\WebstormProjects\discord-bot\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
at async TextChannel.send (C:\Users\issac\WebstormProjects\discord-bot\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.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))
问题是嵌入链接权限被关闭
我正在测试两台服务器,在一台服务器上,该机器人可以运行,但该机器人在另一台服务器上无法运行。
但是,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:\Users\issac\WebstormProjects\discord-bot\node_modules\discord.js\src\rest\RequestHandler.js:350
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Missing Permissions
at RequestHandler.execute (C:\Users\issac\WebstormProjects\discord-bot\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (C:\Users\issac\WebstormProjects\discord-bot\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
at async TextChannel.send (C:\Users\issac\WebstormProjects\discord-bot\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.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))
问题是嵌入链接权限被关闭