Could not locate the term 'group member'

I am currently working on developing a moderation bot using Discord.js v13. In order to implement functionalities such as mute, kick, warn, and ban commands, I need to verify user permissions. However, I am encountering an issue with my code where it fails to compile with the error message "Cannot find name 'member'". Despite referring to the documentation and following the provided methods, I am still facing this issue.

The problematic line in my TypeScript code is line 67. Although I have written this code in TypeScript, I believe that it should not be influencing the occurrence of this error.

import { User, Permissions } from "discord.js";
import { SlashCommandBuilder } from "@discordjs/builders";
import mongoose from "mongoose";
import punishmentSchema from "./schemas/punishment-schema";
const config = require("./config.json");

const client = new Discord.Client({
    intents: [
        Discord.Intents.FLAGS.GUILDS,
        Discord.Intents.FLAGS.GUILD_MESSAGES,
        Discord.Intents.FLAGS.GUILD_MEMBERS
    ]
});

client.on("ready", async () => {
    console.log("Ready for your orders, boss!");

    await mongoose.connect(`${config.mongodb_uri}`, {
        keepAlive: true,
    });

    const guildId = "868810640913989653";
    const guild = client.guilds.cache.get(guildId);
    let commands;

    if(guild) {
        commands = guild.commands;
    } else {
        commands = client.application?.commands;
    }

    commands?.create({
        name: "ping",
        description: "Shows the bot's latency.",
    });
    commands?.create({
        name: "help",
        description: "Lists all commands and shows their usage.",
    });
    commands?.create({
        name: "mute",
        description: "Allows moderators to mute users.",
    });
    commands?.create({
        name: "ban",
        description: "Allows moderators to ban users.",
    });
});

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

    const { commandName, options } = interaction;

    if(commandName === "ping") {
        interaction.reply({
            content: `Current latency: \`\`${client.ws.ping}ms\`\``,
            ephemeral: false,
        })
    } else if(commandName === "help") { 
        interaction.reply({
            content: `**__List of available commands:__**\n\n**/ping** Shows the bot's latency.\n**/help** Guess what this one does :thinking:\n**/cases** Allows non-moderators to check their punishment history.\n\n**/warn {user} [reason]** Applies a warning to a user. :shield:\n**/kick {user} [reason]** Kicks a user from the server. :shield:\n**/mute {user} [duration] [reason]** Kicks a user from the server. :shield:\n**/mute {user} [duration] [reason]** Mutes a user. :shield:\n**/ban {user} [duration] [reason]** Bans a user from the server. :shield:\n**/history {user}** Shows the punishment history of a user. :shield:`,
            ephemeral: false,
        })
    } else if(commandName === "mute") { 
        if (member.permissions.has(Permissions.FLAGS.KICK_MEMBERS)) {
            console.log('test if kick');
        }
    } else if(commandName === "mute") { 
    } 
});

client.login(config.token);

Answer №1

As per the documentation, it is stated that the interaction object must contain a member property. You can access it using interaction.member or by destructuring like this:

const { commandName, options, member } = interaction;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The table appears to be fixed in place and will not scroll, even though the data

Previously, my code was functioning perfectly with the mCustomScrollbar I implemented to scroll both vertically and horizontally on my table. However, while revising my jQuery code for organization purposes, I seem to have unknowingly altered something tha ...

Requesting Next Page via Angular GET Method for Paginated API

Having trouble loading data from a paginated REST API using the code below. Any suggestions for a better approach are welcome! component.ts import { Component, OnInit } from '@angular/core'; import {HttpClient} from '@angular/common/http&a ...

Getting the expanded row columns values in a RadGrid when using the onHierarchyExpanded event

Here is the code for my RadGrid: <telerik:RadGrid ID="ProductRanges_Grd" ShowHeaderWhenEmpty="true" runat="server" AutoGenerateColumns="false" Width="100%" Height="250px" ShowHeader="true" Visible="false" ...

The Serverless Function has exceeded its time limit

While working on a chat app using the MERN stack, I encountered an issue after deploying the server on Vercel. Unfortunately, the app is not functioning properly and the Vercel log shows an error. Legacy server listening... MongoServerError: bad auth : au ...

Utilize the return value within a .map function following the completion of a request.get call

Essentially, for security reasons, I need to convert an image from a URL to base64. Currently, I have two functions in place. One function is responsible for converting the image from the URL to base64, and the other function is iterating over the databas ...

How to delete vertices and their properties from a BufferGeometry using Three.js

In my Three.js project, I have a large collection of point cloud forms grouped together in a single Points object for efficient rendering using BufferGeometry in WebGLRenderer. The program allows users to interactively select a form from the point cloud, w ...

There seems to be an issue with the designated installation directory and it does not match wampserver

While attempting to install Wamp, I encountered an issue where the installation folder chosen was not that of Wampserver. No matter how many times I tried to change the folder, the error persisted. I even attempted installing the x86 version, but that didn ...

Error 404 occurs when the browser reloads the URL for a specific router route

After uploading my Angular 4 app to a production server, I encountered an issue where the pages work fine when accessed through links but return a 404 error when trying to access them directly via URL. I read about resolving this with .htacces on Apache ...

I am having trouble with a basic AJAX script using iframes. The first call returns a null element, but all subsequent calls work perfectly. What am I missing?

An AJAX script that performs the following sequence of actions: Creates a hidden iframe to buffer server-side output Loads PHP content silently into a div using the iframe Copies the PHP output from the server-side div to the parent page div The issue e ...

Designing a Custom Wordpress Extension and Integrating External Scripts

As I dive into the world of WordPress plugin development, I'm seeking guidance from the codex to enhance my skills. Currently, I have a basic plugin that loads a javascript file from a CDN and is supposed to display tooltips. However, I'm facing ...

Converting React to Typescript and refactoring it leads to an issue where the property 'readOnly' is not recognized on the type 'IntrinsicAttributes & InputProps & { children?: ReactNode; }'

I'm currently in the process of refactoring an application using Typescript. Everything is going smoothly except for one particular component. I am utilizing the Input component from the library material-ui. import {Input} from "material-ui"; class ...

Unable to substitute 'npm run build' for 'webpack' command

I'm having trouble with npm run build not calling webpack as expected. I've modified the script in my package.json file, but it didn't work. I'm using Linux. Here is a snippet from my package.json file: { "name": "learn-webpack", ...

Troubleshooting a jQuery carousel: How can I prevent the thumbnails from automatically moving forward?

I am currently modifying a carousel where the thumbnails are moving out of frame. I need assistance in keeping them stationary, except for the blue thumbnail highlighter. To better illustrate the issue, I have created a jsFiddle here: http://jsfiddle.net ...

Transferring PointLight Parameters to a Custom Shader using three.js

I am looking to achieve a similar effect as the undulating sphere demonstrated in the Aerotwist Tutorial. Instead of using a fake GLSL hard-coded light like in the tutorial, I am interested in passing information from a three.js PointLight instance to my s ...

Trouble with React Native Maps: Region not refreshing, causing map to remain stuck on a single location

My <MapView> is not updating the region properly when I scroll the map. It seems to be stuck on one region and doesn't update as expected. Even when I scroll, the same region is passed to this.props.onRegionChange, preventing the map from actual ...

utilizing a pair of API requests within a personalized Alexa skill

I posted a question about integrating Alexa with the Steam custom skill API here, but I realize it might be too detailed for some to read through. In essence, my main question is: Can you make two separate API calls within the same block of JS code while ...

Unusual problem arises with scoping when employing typeguards

Consider the following TypeScript code snippet: interface A { bar: string; } const isA = <T>(obj: T): obj is T & A => { obj['bar'] = 'world'; return true; } let obj = { foo: 'hello' }; if (!isA(obj)) thro ...

Trying to configure and use two joysticks at the same time using touch events

I have been grappling with this problem for the past two days. My current project involves using an HTML5/JS game engine called ImpactJS, and I came across a helpful plugin designed to create joystick touch zones for mobile devices. The basic concept is th ...

Expanding the sidebar panel during a redirection

I am facing an issue with the expansion panels in my sidenav. I have successfully been able to track and set their open state as they are opened and closed. However, when a list item within the panel is clicked and redirects to another route, the panel c ...

Having issues with the link page in react-router-dom?

Currently, I am utilizing the react-router-dom library to manage routers. However, I have encountered an issue where linking to another page does not change the page, but instead adds the new page right after the previous one as shown in the image below. W ...