首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >TypeError: Object.hasOwn不是一个函数

TypeError: Object.hasOwn不是一个函数
EN

Stack Overflow用户
提问于 2022-07-23 16:50:24
回答 1查看 2.6K关注 0票数 6

我试图用新的discord.js版本编写一个机器人,但是当我尝试登录时,它会提示我这个错误

代码语言:javascript
运行
复制
/home/max/Schreibtisch/Discord Bots/Perplex/node_modules/discord.js/src/util/Util.js:279
    if (!Object.hasOwn(given, key) || given[key] === undefined) {
                ^

TypeError: Object.hasOwn is not a function
    at mergeDefault (/home/max/Schreibtisch/Discord Bots/Perplex/node_modules/discord.js/src/util/Util.js:279:17)
    at new BaseClient (/home/max/Schreibtisch/Discord Bots/Perplex/node_modules/discord.js/src/client/BaseClient.js:25:20)
    at new Client (/home/max/Schreibtisch/Discord Bots/Perplex/node_modules/discord.js/src/client/Client.js:43:5)
    at Object.<anonymous> (/home/max/Schreibtisch/Discord Bots/Perplex/src/bot.js:26:16)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47

这是我的机器人代码

代码语言:javascript
运行
复制
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.on('ready', () => {
    console.log(`Logged in as ${client.user.tag}!`);
});

client.on('interactionCreate', async (interaction) => {
    if (!interaction.isChatInputCommand()) return;

    if (interaction.commandName === 'ping') {
        await interaction.reply('Pong!');
    }
});

client.login('token');
EN

回答 1

Stack Overflow用户

发布于 2022-07-23 17:20:32

我不认为这个代码片段中有错误。如果这是您的src/bot.js文件,那么它似乎没有问题。

但是,错误说"Object.hasOwn不是一个函数“,Object.hasOwn只在node.js v16.9.0之后才可用。

Discord.js v14需要node.js 16.9或更高版本,所以请确保您是最新的。若要检查节点版本,请在终端或命令提示符中使用node -v,如果它比此更旧,则使用update it

要了解更多的突破性更改,您可以查看以下答案:Discord.js v13 code breaks when upgrading to v14

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73092593

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档