MatteZ02 / discord-interactions

A simple to use discord interactionClient
MIT License
33 stars 5 forks source link

encountering an error while using .deleteCommand() #1

Closed Assassin-1234 closed 3 years ago

Assassin-1234 commented 3 years ago

hey ! I tried using the .deleteCommand('my command ID') but encountered a weird error,

I have no idea what this error is about

my code -

discordclient.on('ready', async () => {
    client.deleteCommand("789520844543098881").then(console.log);
})

my error -

Error: Request failed with status code 401
    at createError (C:\Users\chord\Desktop\slash commands\node_modules\axios\lib\core\createError.js:16:15)
    at settle (C:\Users\chord\Desktop\slash commands\node_modules\axios\lib\core\settle.js:17:12)
    at IncomingMessage.handleStreamEnd (C:\Users\chord\Desktop\slash commands\node_modules\axios\lib\adapters\http.js:244:11)
    at IncomingMessage.emit (events.js:322:22)
    at endReadableNT (_stream_readable.js:1187:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  config: {
    url: 'https://discord.com/api/v8/applications/779741162465525790/commands/789520844543098881',
    method: 'delete',
    headers: {
      Accept: 'application/json, text/plain, */*',
      'User-Agent': 'axios/0.21.0'
    },
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    adapter: [Function: httpAdapter],
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    validateStatus: [Function: validateStatus],
    data: undefined
  },
  request: ClientRequest {
    _events: [Object: null prototype] {
      socket: [Function],
      abort: [Function],
      aborted: [Function],
      connect: [Function],
      error: [Function],
      timeout: [Function],
      prefinish: [Function: requestOnPrefinish]
    },
    _eventsCount: 7,
    _maxListeners: undefined,
    outputData: [],
    outputSize: 0,
    writable: true,
    _last: true,
    chunkedEncoding: false,
    shouldKeepAlive: false,
    useChunkedEncodingByDefault: false,
    sendDate: false,
    _removedConnection: false,
    _removedContLen: false,
    _removedTE: false,
    _contentLength: 0,
    _hasBody: true,
    _trailer: '',
    finished: true,
    _headerSent: true,
    socket: TLSSocket {
      _tlsOptions: [Object],
      _secureEstablished: true,
      _securePending: false,
      _newSessionPending: false,
      _controlReleased: true,
      _SNICallback: null,
      servername: 'discord.com',
      alpnProtocol: false,
      authorized: true,
      authorizationError: null,
      encrypted: true,
      _events: [Object: null prototype],
      _eventsCount: 10,
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: 'discord.com',
      _readableState: [ReadableState],
      readable: true,
      _maxListeners: undefined,
      _writableState: [WritableState],
      writable: false,
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: undefined,
      _server: null,
      ssl: [TLSWrap],
      _requestCert: true,
      _rejectUnauthorized: true,
      parser: null,
      _httpMessage: [Circular],
      [Symbol(res)]: [TLSWrap],
      [Symbol(asyncId)]: 890,
      [Symbol(kHandle)]: [TLSWrap],
      [Symbol(kSetNoDelay)]: false,
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kCapture)]: false,
      [Symbol(kBytesRead)]: 0,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(connect-options)]: [Object]
    },
    connection: TLSSocket {
      _tlsOptions: [Object],
      _secureEstablished: true,
      _securePending: false,
      _newSessionPending: false,
      _controlReleased: true,
      _SNICallback: null,
      servername: 'discord.com',
      alpnProtocol: false,
      authorized: true,
      authorizationError: null,
      encrypted: true,
      _events: [Object: null prototype],
      _eventsCount: 10,
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: 'discord.com',
      _readableState: [ReadableState],
      readable: true,
      _maxListeners: undefined,
      _writableState: [WritableState],
      writable: false,
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: undefined,
      _server: null,
      ssl: [TLSWrap],
      _requestCert: true,
      _rejectUnauthorized: true,
      parser: null,
      _httpMessage: [Circular],
      [Symbol(res)]: [TLSWrap],
      [Symbol(asyncId)]: 890,
      [Symbol(kHandle)]: [TLSWrap],
      [Symbol(kSetNoDelay)]: false,
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kCapture)]: false,
      [Symbol(kBytesRead)]: 0,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(connect-options)]: [Object]
    },
    _header: 'DELETE /api/v8/applications/779741162465525790/commands/789520844543098881 HTTP/1.1\r\n' +
      'Accept: application/json, text/plain, */*\r\n' +
      'User-Agent: axios/0.21.0\r\n' +
      'Host: discord.com\r\n' +
      'Connection: close\r\n' +
      '\r\n',
    _onPendingData: [Function: noopPendingOutput],
    agent: Agent {
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      defaultPort: 443,
      protocol: 'https:',
      options: [Object],
      requests: {},
      sockets: [Object],
      freeSockets: {},
      keepAliveMsecs: 1000,
      keepAlive: false,
      maxSockets: Infinity,
      maxFreeSockets: 256,
      maxCachedSessions: 100,
      _sessionCache: [Object],
      [Symbol(kCapture)]: false
    },
    socketPath: undefined,
    method: 'DELETE',
    insecureHTTPParser: undefined,
    path: '/api/v8/applications/779741162465525790/commands/789520844543098881',
    _ended: true,
    res: IncomingMessage {
      _readableState: [ReadableState],
      readable: false,
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      socket: [TLSSocket],
      connection: [TLSSocket],
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      headers: [Object],
      rawHeaders: [Array],
      trailers: {},
      rawTrailers: [],
      aborted: false,
      upgrade: false,
      url: '',
      method: null,
      statusCode: 401,
      statusMessage: 'Unauthorized',
      client: [TLSSocket],
      _consuming: false,
      _dumped: false,
      req: [Circular],
      responseUrl: 'https://discord.com/api/v8/applications/779741162465525790/commands/789520844543098881',
      redirects: [],
      [Symbol(kCapture)]: false
    },
    aborted: false,
    timeoutCb: null,
    upgradeOrConnect: false,
    parser: null,
    maxHeadersCount: null,
    reusedSocket: false,
    _redirectable: Writable {
      _writableState: [WritableState],
      writable: true,
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      _options: [Object],
      _ended: true,
      _ending: true,
      _redirectCount: 0,
      _redirects: [],
      _requestBodyLength: 0,
      _requestBodyBuffers: [],
      _onNativeResponse: [Function],
      _currentRequest: [Circular],
      _currentUrl: 'https://discord.com/api/v8/applications/779741162465525790/commands/789520844543098881',
      [Symbol(kCapture)]: false
    },
    [Symbol(kCapture)]: false,
    [Symbol(kNeedDrain)]: false,
    [Symbol(corked)]: 0,
    [Symbol(kOutHeaders)]: [Object: null prototype] {
      accept: [Array],
      'user-agent': [Array],
      host: [Array]
    }
  },
  response: {
    status: 401,
    statusText: 'Unauthorized',
    headers: {
      date: 'Fri, 18 Dec 2020 16:37:25 GMT',
      'content-type': 'application/json',
      'content-length': '43',
      connection: 'close',
      'set-cookie': [Array],
      'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
      'x-envoy-upstream-service-time': '5',
      via: '1.1 google',
      'cf-cache-status': 'DYNAMIC',
      'cf-request-id': '07184fac150000397e24082000000001',
      'expect-ct': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
      'report-to': '{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report?s=tga6kYFg6pm2T0tPYnXasSg67Ntt%2F4uhBlab38gA1zlhwbreFzv8VgrN7n%2FbSnCVkr7pGpjx8T2ZLrmarCUnWbCrX0J5FeFvC0tlsg%3D%3D"}],"group":"cf-nel","max_age":604800}',
      nel: '{"report_to":"cf-nel","max_age":604800}',
      'x-content-type-options': 'nosniff',
      server: 'cloudflare',
      'cf-ray': '603a4ef35f98397e-MAA'
    },
    config: {
      url: 'https://discord.com/api/v8/applications/779741162465525790/commands/789520844543098881',
      method: 'delete',
      headers: [Object],
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      adapter: [Function: httpAdapter],
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      validateStatus: [Function: validateStatus],
      data: undefined
    },
    request: ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      socket: [TLSSocket],
      connection: [TLSSocket],
      _header: 'DELETE /api/v8/applications/779741162465525790/commands/789520844543098881 HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'User-Agent: axios/0.21.0\r\n' +
        'Host: discord.com\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _onPendingData: [Function: noopPendingOutput],
      agent: [Agent],
      socketPath: undefined,
      method: 'DELETE',
      insecureHTTPParser: undefined,
      path: '/api/v8/applications/779741162465525790/commands/789520844543098881',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    data: { message: '401: Unauthorized', code: 0 }
  },
  isAxiosError: true,
  toJSON: [Function: toJSON]
}
(node:9448) UnhandledPromiseRejectionWarning: An error has occured!
(node:9448) 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: 2)
(node:9448) [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 code.

any help would be appreciated !

MatteZ02 commented 3 years ago

Mind sharing how you initialized the client?

VeraxonHD commented 3 years ago

Hello! I'm having the same issue. For the record, my client is initialized like so:

const Discord = require("discord.js");
const interactions = require("discord-slash-commands-client");

const client = new Discord.Client();
client.interactions = new interactions.Client(
    config.token,
    "789655175048331283"
);
MatteZ02 commented 3 years ago

Have you double checked that config.token is a valid token? If it is there might be a bug with the headers for deleting commands (header that authorizes using the token) As i can see from the response Assassin-1234 sent there is no authorization header.

VeraxonHD commented 3 years ago

Yes it's a valid token, it works just fine when calling client.login()

MatteZ02 commented 3 years ago

Alright. This should have been fixed in the latest update i just pushed. If you can give it a shot.

VeraxonHD commented 3 years ago

Will do, give me a moment!

VeraxonHD commented 3 years ago

Yep, that patch seems to be working on my end! Nothing is logged to console, however - even with .then(console.log)

MatteZ02 commented 3 years ago

Thats weird. Did it just log undefined or ?

VeraxonHD commented 3 years ago

I think it's printing an empty string? There's a newline in my console with nothing in it.

MatteZ02 commented 3 years ago

can u attach a screenshot of ur console?

VeraxonHD commented 3 years ago

image Image 1: Code

image Image 2: Output

Note the blank line between "Bot Loaded" and "Created Command"

MatteZ02 commented 3 years ago

i see. Ill have to check the response from deleting. Might be that there's no response or something like that.

Assassin-1234 commented 3 years ago

I really appreciate your help ! tysm I can delete my command successfully, I can confirm that its not logging anything image

MatteZ02 commented 3 years ago

Alright! Thats good.