TypeError: option.getMember("target) is not a function
TypeError: option.getMember("target) is not a function
所以我做了这个踢命令并完成了编码。现在我收到了这个错误并且完全不知道如何修复它。我在互联网上搜索了一个小时,仍然不知道问题出在哪里。
这里是错误:
TypeError: options.getMember is not a function
at Object.execute (/Users/Aplex/Documents/Aplel/Commands/Moderation/kick.js:32:32)
at Object.execute (/Users/Aplex/Documents/Aplel/Events/Interaction/interactionCreate.js:21:21)
at Client.<anonymous> (/Users/Aplex/Documents/Aplel/Structures/Handlers/Events.js:18:54)
at Client.emit (node:events:538:35)
at InteractionCreateAction.handle (/Users/Aplex/Documents/Aplel/node_modules/discord.js/src/client/actions/InteractionCreate.js:74:12)
at Object.module.exports [as INTERACTION_CREATE] (/Users/Aplex/Documents/Aplel/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (/Users/Aplex/Documents/Aplel/node_modules/discord.js/src/client/websocket/WebSocketManager.js:351:31)
at WebSocketShard.onPacket (/Users/Aplex/Documents/Aplel/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/Users/Aplex/Documents/Aplel/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/Users/Aplex/Documents/Aplel/node_modules/ws/lib/event-target.js:199:18)
这是我的代码:
const { Client, CommandInteraction } = require("discord.js");
module.exports = {
name: "kick",
description: "Kick a member",
userPermission: ["KICK_MEMBERS"],
options: [
{
name: "target",
description: "target to kick",
type: "USER",
required: true
},
{
name: "reason",
description: "reason for this kick",
type: "STRING",
required: false,
}
],
/**
*
* @param {Client} client
* @param {CommandInteraction} interaction
* @param {String} args
*/
execute: async(client, interaction, args) => {
const { options, member } = interaction;
const target = options.getMember("target");
const reason = options.getString("reason") || "No reason provided";
if(!target.roles.highest.position >= member.roles.highest.position) return interaction.followUp({content: "You can't take action on this user as their role is higher than yours!",
});
await target.send(`You have been kicked from ${interaction.guild.name}, reason ${reason}`);
target.kick(reason);
interaction.followUp({content: `Kicked ${target.user.tag} successfully! reason: ${reason}`});
},
};
有人知道问题出在哪里吗?如果有人帮助,将不胜感激!
我可以假设您正在学习 lyxcode 教程吗?
如果有,在行
execute(client, interaction, args)
改为
execute(interaction, client, args)
这应该与您的 interactionCreate 文件匹配。
另外,将 followUp
更改为 reply
希望这能帮您解决问题![=14=]
如果您正在尝试获取会员的帐户缓存,也许您应该尝试这样的操作:
client.members.cache.get('User ID');
所以我做了这个踢命令并完成了编码。现在我收到了这个错误并且完全不知道如何修复它。我在互联网上搜索了一个小时,仍然不知道问题出在哪里。
这里是错误:
TypeError: options.getMember is not a function
at Object.execute (/Users/Aplex/Documents/Aplel/Commands/Moderation/kick.js:32:32)
at Object.execute (/Users/Aplex/Documents/Aplel/Events/Interaction/interactionCreate.js:21:21)
at Client.<anonymous> (/Users/Aplex/Documents/Aplel/Structures/Handlers/Events.js:18:54)
at Client.emit (node:events:538:35)
at InteractionCreateAction.handle (/Users/Aplex/Documents/Aplel/node_modules/discord.js/src/client/actions/InteractionCreate.js:74:12)
at Object.module.exports [as INTERACTION_CREATE] (/Users/Aplex/Documents/Aplel/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (/Users/Aplex/Documents/Aplel/node_modules/discord.js/src/client/websocket/WebSocketManager.js:351:31)
at WebSocketShard.onPacket (/Users/Aplex/Documents/Aplel/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/Users/Aplex/Documents/Aplel/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/Users/Aplex/Documents/Aplel/node_modules/ws/lib/event-target.js:199:18)
这是我的代码:
const { Client, CommandInteraction } = require("discord.js");
module.exports = {
name: "kick",
description: "Kick a member",
userPermission: ["KICK_MEMBERS"],
options: [
{
name: "target",
description: "target to kick",
type: "USER",
required: true
},
{
name: "reason",
description: "reason for this kick",
type: "STRING",
required: false,
}
],
/**
*
* @param {Client} client
* @param {CommandInteraction} interaction
* @param {String} args
*/
execute: async(client, interaction, args) => {
const { options, member } = interaction;
const target = options.getMember("target");
const reason = options.getString("reason") || "No reason provided";
if(!target.roles.highest.position >= member.roles.highest.position) return interaction.followUp({content: "You can't take action on this user as their role is higher than yours!",
});
await target.send(`You have been kicked from ${interaction.guild.name}, reason ${reason}`);
target.kick(reason);
interaction.followUp({content: `Kicked ${target.user.tag} successfully! reason: ${reason}`});
},
};
有人知道问题出在哪里吗?如果有人帮助,将不胜感激!
我可以假设您正在学习 lyxcode 教程吗?
如果有,在行
execute(client, interaction, args)
改为
execute(interaction, client, args)
这应该与您的 interactionCreate 文件匹配。
另外,将 followUp
更改为 reply
希望这能帮您解决问题![=14=]
如果您正在尝试获取会员的帐户缓存,也许您应该尝试这样的操作:
client.members.cache.get('User ID');