【发布时间】:2021-10-24 04:40:55
【问题描述】:
我在启动代码时收到此错误消息:UnhandledPromiseRejectionWarning: Error: Server responded with 403 我该如何解决?
我的代码:
client.on('guildMemberAdd', async (member, guild) => {
const leftright = 147;
const upkdown = 138;
const ksize = 240;
const namleftright04 = 310;
const namupdown14 = 155;
let textsize = 25;
const canvas = Canvas.createCanvas(705,290);
const ctx = canvas.getContext('2d');
const WelcomeImage = await Canvas.loadImage("./image.png");
ctx.drawImage(WelcomeImage, 0, 0, canvas.width, canvas.height);
ctx.font = `${textsize}px px Arial`;
ctx.shadowColor = 'rgba(22, 22, 22, 1)';
ctx.shadowOffsetY = 1;
ctx.shadowBlur = 1;
ctx.fillStyle = 'WHITE';
ctx.fillText(member.user.username, namleftright04, namupdown14);
ctx.beginPath();
ctx.arc(leftright, upkdown, ksize/2, 0, Math.PI * 2, true);
ctx.closePath();
ctx.clip();
const avatarUser = await Canvas.loadImage(
member.user.avatarURL({ format: 'jpg' })
);
ctx.drawImage(
avatarUser,
leftright - 120,
upkdown - 120,
ksize,
ksize
)
const attachment = new Discord.MessageAttachment(
canvas.toBuffer(),
'welcome.png'
);
const channel = member.guild.channels.cache.find(ch => ch.id == '870381834624700447');
channel.send(attachment);
});
我收到了这个错误:
(node:11608) UnhandledPromiseRejectionWarning: Error: Server responded with 403
at C:\Users\user\Desktop\make\node_modules\canvas\lib\image.js:56:28
at C:\Users\user\Desktop\make\node_modules\simple-get\index.js:89:7
at IncomingMessage.<anonymous> (C:\Users\user\Desktop\make\node_modules\simple-concat\index.js:8:13)
at Object.onceWrapper (events.js:519:28)
at IncomingMessage.emit (events.js:412:35)
at endReadableNT (internal/streams/readable.js:1317:12)
at processTicksAndRejections (internal/process/task_queues.js:82:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:11608) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:11608) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit
【问题讨论】:
-
403 通常意味着,即使服务器能够成功地对用户进行身份验证,该经过身份验证的用户也不允许访问所请求的资源(例如,非管理员试图访问一些仅限于管理员的值,或者用户 x 正在尝试访问属于用户 y 的资源)假设权限管理在服务器上正常工作,解决此问题的唯一方法是为允许访问请求的资源或仅请求的用户提供凭据当前用户可以访问的资源。
-
您是否按照错误日志中的建议使用了
node --trace-warnings ...? -
403 表示“禁止”。您可能有身份验证问题。
标签: javascript node.js canvas discord discord.js