Voice channel userlimit discord js - discord.js

I'm trying to create a voice channel with Discord Bot
. This is my code simply (I'm using discord.js)
message.channel.createChannel('General', "voice").then(chan => {
chan.userLimit("5");
})
But the console log is like that
(node:13080) UnhandledPromiseRejectionWarning: TypeError: message.channel.createChannel is not a function
How can I handle of this?

You can not use the .createChannel method on a channel, you need to use it on a guild.
This would be correct:
discord.js v11
message.guild.createChannel();
discord.js v12
message.guild.channels.create();

Related

Uncaught ErrorClass ErrorClass in discord.js

My bot was working fine. Using a slash command /close the bot saved the messages of a channel in hastebin and deleted the channel. I added another command to update roles, it works fine but after using it one time the "close" command doesn't work anymore, even if I remove the "update permissions" command from the command's folder.
I figured out the problem is in the "close" command, in particular when I fetch the channel messages. If I don't fetch the messages I don't get any error, but leaving it as it was causes the error below. Once again, the command was working fine before adding and using the "update permissions" . I googled this error but I can't find anything about it. I don't know if u need the code, the problem is just in the fetch messages step. I tried over and over again, and I don't get why it doesn't work anymore.
chan.messages.fetch().then(async (messages) => {
Uncaught ErrorClass ErrorClass
at processPromiseRejections (internal/process/promises:288:13)
at processTicksAndRejections (internal/process/task_queues:96:32)

Why are commands not working for my discord.py bot?

`
import os
import discord
from dotenv import load_dotenv
from discord.ext import commands
from discord import FFmpegPCMAudio
load_dotenv(".env")
TOKEN = os.getenv("DISCORD_TOKEN")
client = commands.Bot(command_prefix='$')
#client.command()
async def unvc(ctx):
await ctx.guild.voice_client.disconnect()
#client.command()
async def vc(ctx):
if ctx.author.voice:
channel = ctx.author.voice.channel
await channel.connect()
source = FFmpegPCMAudio('music.mp3')
player = voice.play(source)
#client.event
async def on_ready():
print('{0.user} has connected toDiscord!'.format(client))
return await client.change_presence(
activity=discord.Activity(type=discord.ActivityType.playing, name="anime waifu simulator VR"))
client.run(TOKEN)
`
I am trying to use commands with my discord bot and it does nothing when I type them. It is still able to delete messages, so it isn't an issue with the connection to Discord.
Seems like you‘re using the olde 1.7.3 version of discord.py that is outdated at this time due to new required intents.
check your version with pip show discord.py and should upgrade to 2.x
then you also have to use the message intent if you‘re using the message command framework of discord.py
for that, go to the discord developer dashboard and activate the privileged intent „message“. after that, add the following to your code above your bot definition:
intents = discord.Intents()
intents.message_content = True
then pass the intents to the bot constructor with
intents=intents
(also, normally in discord.py programming, we do name Bot instances bot and only Client instances client)
You have to make the bot listen to both, commands and messages. If you send a message, it will be read as a message and not like a command. For fixing that add:
#client.event
async def on_message(ctx:Context):
await client.process_commands(ctx)
Add this:
intents = discord.Intents.all()
client = commands.Bot(command_prefix='$', intents=intents)
This will add the intents to the bot. I've tried it out. That should work for you. You also have to enable intents in the bot settings in your discord developer portal.

In my bot I'm using my command bot info or my bot joins new guild it getting errors to send the message

When ever I'm using my bot info command it showing this error and i don't know how to solve it
Error
TypeError: Cannot read properties of null (reading 'broadcastEval')
at module.exports (/home/container/src/commands/bot/info.js:7:22)
at Client.client.loadSubcommands (/home/container/src/handlers/functions/functions.js:87:130)
at processTicksAndRejections (node:internal/process/task_queues:96:5)```

How do I resolve the 50001-Error "Missing Access" when trying to register commands for my bot?

I am having some trouble with the registration of commands for my Discord bot.
I am following the tutorial on discordjs.guide, but get an error, where they dont. When I try to run their code, I get an error in the console related to missing access of the bot. I am aware that "applications.commands" needs to be checked in the discord developer portal and that the bot needs to be kicked and re-added to the server, but despite doing all that, the error still remains.
The error looks like this:
DiscordAPIError[50001]: Missing Access
at SequentialHandler.runRequest (<my-folder-path>\node_modules\#discordjs\rest\dist\index.js:753:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.queueRequest (<my-folder-path>\node_modules\#discordjs\rest\dist\index.js:565:14)
at async REST.request (<my-folder-path>\node_modules\#discordjs\rest\dist\index.js:999:22) {
rawError: { message: 'Missing Access', code: 50001 },
code: 50001,
status: 403,
method: 'PUT',
url: 'https://discord.com/api/v9/applications/<my-bot-id>/guilds/<my-guild-id>/commands',
requestBody: { files: undefined, json: [ [Object], [Object], [Object] ] }
}
I have replaced a few irrelevant parts in the message like Ids and folder paths with general statements at "< >" due to privacy reasons.
On thing that differs from the error-message of some other folks with the same problem, is that there is no line in their message stating the request-body like there is in the last line of mine.
The issue could be resolved by adding the "application.commands" permission in the bot settings, but as stated earlier, this didnt work for me. In terms of code, I am using the exact code as in the example, with my specific data filled into the config.json.
My bot has the scopes of "bot" and "application.commands", as well as the bot permissions of "Administrator".
I am very thankful for every response!
Check if the applications.commands scope is checked in the developers portal OAuth2 section.

Error pops up on startup: 'Incorrect login details were provided'

I'm following the guide. I've run node index.js into Windows PowerShell, but it's not giving intended output
It's copy and pasted from the discord.js guide. I've run it many times and every time it has the same exact error.
// require the discord.js module
const Discord = require('discord.js');
// create a new Discord client
const client = new Discord.Client();
// when the client is ready, run this code
// this event will only trigger one time after logging in
client.once('ready', () => {
console.log('Ready!');
});
// login to Discord with your app's token
client.login('your-token-goes-here');
expected: Ready!
actual:
(node:800) UnhandledPromiseRejectionWarning: Error: Incorrect login details were provided.
at WebSocketConnection.client.ws.connection.once.event (C:\Users\mort3\Desktop\Sakabato\node_modules\discord.js\src\client\ClientManager.js:48:41)
at Object.onceWrapper (events.js:276:13)
at WebSocketConnection.emit (events.js:188:13)
at WebSocketConnection.onClose (C:\Users\mort3\Desktop\Sakabato\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:390:10)
at WebSocket.onClose (C:\Users\mort3\Desktop\Sakabato\node_modules\ws\lib\event-target.js:124:16)
at WebSocket.emit (events.js:188:13)
at _receiver.cleanup (C:\Users\mort3\Desktop\Sakabato\node_modules\ws\lib\websocket.js:220:12)
at Receiver.cleanup (C:\Users\mort3\Desktop\Sakabato\node_modules\ws\lib\receiver.js:535:15)
at WebSocket.finalize (C:\Users\mort3\Desktop\Sakabato\node_modules\ws\lib\websocket.js:206:20)
at TLSSocket.emit (events.js:193:15)
(node:800) 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(). (rejection id: 2)
(node:800) [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.
Double check if you have copied the token from the Bot tab, not from General Information tab.
The discord API and discord.js (which is a wrapper for the discord api) require an authentication token. You supply this token on login:
client.login(<insert your token here>)
You are not replacing the filler text your-token-goes-here with your actual authentication token, one that you receive by making an application on discord (See https://discordjs.guide/#/preparations/setting-up-a-bot-application)
To see how I got here, look at the stack trace, the error message:
Error: Incorrect login details were provided.
It's pretty self-evident what the error is; in this case, you didn't supply any login details.
It says
Error: Incorrect login details were provided
You need to get a bot token via the Discord Developer Dashboard, create an application there, convert it to a Bot account and from there you can get the needed token to use in the client.loginmethod.
Make sure to never show anyone this token.
you need to create a token for the bot to connect with the Discord API

Resources