discord / discord-api-docs

Official Discord API Documentation
https://discord.com/developers/docs/intro
Other
5.96k stars 1.26k forks source link

Autocomplete slash command appear only one admin #4643

Closed copyNdpaste closed 2 years ago

copyNdpaste commented 2 years ago

Description

I created slash command bot with bot, applications.commands scopes. And create slash command for guild, and command not showed so I create commands as application scope. And still not showing

I tried to kick out my bot and re enter url but not worked...

What is the solution plz! Thank you

Steps to Reproduce

const serverless = require("serverless-http");
const express = require("express");
const app = express();
const { CreateRateUseCase } = require("./core/usecase/createRateUseCase");
const nacl = require("tweetnacl");
const getRawBody = require("raw-body");
const { DiscordBot } = require("./discordBot");
// const { verifyKeyMiddleware } = require("discord-interactions");
require("dotenv").config({ path: `./.env.${process.env.NODE_ENV}` });

app.post(
  "/interactions",
  // verifyKeyMiddleware(process.env.DISCORD_PUBLIC_KEY),
  async (req, res, next) => {
    try {
      console.log(`req : `);
      console.log(req);
      console.log(`body ${req.body} ${JSON.stringify(req.body)}`);

      const rawBody = await getRawBody(req);
      console.log(`rawBody ${rawBody} ${typeof rawBody}`);

      const body = JSON.parse(rawBody);

      if (
        process.env.NODE_ENV === "dev" ||
        process.env.NODE_ENV === "production"
      ) {
        const signature = req.get("X-Signature-Ed25519");
        console.log(`signature ${signature}`);
        const timestamp = req.get("X-Signature-Timestamp");
        console.log(`timestamp ${timestamp}`);
        const isVerified = nacl.sign.detached.verify(
          Buffer.from(timestamp + rawBody),
          Buffer.from(signature, "hex"),
          Buffer.from(process.env.DISCORD_PUBLIC_KEY, "hex")
        );
        console.log(`isVerified ${isVerified}`);
        if (!isVerified) {
          console.log("Failed verification");
          return res.status(401).end("invalid request signature");
        }

        if (body.type === 1) {
          console.log("Handling validation test request");
          return res.status(200).send({ type: 1 });
        }
      }

      if (body.type === 2) {
        if (
          body.channel_id !== process.env.DISCORD_CHANNEL_ID_KOR &&
          body.channel_id !== process.env.DISCORD_CHANNEL_ID_EN
        ) {
          console.log(`channel id ${body.channel_id}`);
          console.log(
            "This command is only available in the COMMUNITY category"
          );
          res.status(200).send({
            type: 4,
            data: {
              content: `This command is only available in the 'COMMUNITY' category. 😒`,
            },
          });
          return;
        }

        const discordBot = new DiscordBot();
        const result = await discordBot.execute(body);
        console.log(`result ${JSON.stringify(result)}`);

        res.status(200).send(result);
        console.log("reply done");
      }
      return;
    } catch (e) {
      console.error(e.message);
      return res.send("Error handling verification");
    }
  }
);
  1. deploy server on aws lambda
  2. OAuth2 -> URL Generator, check bot, applications.commands and enter url then select server.
  3. check SERVER MEMBERS INTENT, MESSAGE CONTENT INTENT
  4. enter api gateway url to INTERACTIONS ENDPOINT URL as https://xyz.amazonaws.com/interactions/
  5. create slash commands
    
    const { Client, Intents } = require("discord.js");
    const client = new Client({
    intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
    });
    console.log(`NODE_ENV ${process.env.NODE_ENV}`);
    require("dotenv").config({ path: `./.env.${process.env.NODE_ENV}` });

const korCommandList = { γ……γ…‡γ„Ή: { description: "예치 수읡λ₯  응닡", }, 수읡λ₯ : { description: "예치 수읡λ₯  응닡", }, 예치수읡λ₯ : { description: "예치 수읡λ₯  응닡", }, }; const enCommandList = { depositapy: { description: "response deposit yield", }, yield: { description: "response deposit yield", }, apy: { description: "response deposit yield", }, deposityield: { description: "response deposit yield", }, };

client.on("ready", async () => { const promises = []; const objs = Object.assign(korCommandList, enCommandList); console.log( process.env.DISCORD_BOT_CLIENT_ID ${process.env.DISCORD_BOT_CLIENT_ID} ); console.log(process.env.DISCORD_GUILD_ID ${process.env.DISCORD_GUILD_ID}); for (const key in objs) { const p = await client.api .applications(process.env.DISCORD_BOT_CLIENT_ID) // .guilds(process.env.DISCORD_GUILD_ID) .commands.post({ data: { name: key, description: objs[key].description, }, }); promises.push(p); } const result = await Promise.all(promises); console.log(result);

client.destroy(); });

client.login(process.env.DISCORD_BOT_TOKEN);


6. after hours, or day type `/` on discord app. normal user can not see commad list, but admin can see.

### Expected Behavior

Every user on server with bot can see slash command list.

### Current Behavior

Admin can see slash command lists, but normal user can not see.

### Screenshots/Videos

text box by server admin
![image](https://user-images.githubusercontent.com/18900976/158046526-e175aa10-cfc3-49a6-934e-33015b0ea741.png)

text box by server normal user, slash commands not displayed
<img width="257" alt="image" src="https://user-images.githubusercontent.com/18900976/158046537-df1f69a6-f4bd-491c-94e6-1ea9aa8e143c.png">

### Client and System Information

browser admin : chrome on mac 
![image](https://user-images.githubusercontent.com/18900976/158046573-d1042d1f-2533-4126-8327-c9af3f01a631.png)

user : discord app on mac
<img width="164" alt="image" src="https://user-images.githubusercontent.com/18900976/158046577-ef02e53c-156a-4401-83a0-b0fe2b18caf9.png">

lib 
![image](https://user-images.githubusercontent.com/18900976/158046559-e0146ca3-6c11-439a-b906-822580744fde.png)
advaith1 commented 2 years ago

It looks like the user doesn't have the "Use Application Commands" permission in the server; this is not related to the bot.

copyNdpaste commented 2 years ago

@advaith1 How to user add "Use Application Commands" permission on server? :)

advaith1 commented 2 years ago

You can modify role permissions in Server Settings: https://support.discord.com/hc/en-us/articles/206029707-Setting-Up-Permissions-FAQ

for Discord support go to https://dis.gd/support

copyNdpaste commented 2 years ago

@advaith1 Thank you! I found the solution. I checked use application command on permission of channel edit. I tried to check use application command on server configure beside server name, but it not worked.

this one

image

not this image