dmPermission property not working on discord.js v14 - discord

I noticed my discord bot commands were showing up in DMs too, which I didn't want. So I added
dmPermission: false,
to all of them. I refreshed the / commands and I can still see and run the commands in my DMs with the bot. How can I fix this?
Here is an example:
{
name: 'setchannel',
description: 'Sets the channel in which certain messages should be sent',
dmPermission: false,
options: [
...
]
}

Related

Slash commands only work on one Discord server? (discord.js v13)

I noticed that slash commands only work on one Discord server: bot.guilds.cache.get(<GUILD_ID>).commands.set(command.name, command).
Is there really no way to make the commands work right away on those servers where the bot already exists? Do I have to add IDs separately? I tried bot.guilds.cache.map(guild => guild.id).commands.set(command.name, command), but it gives an error TypeError: Cannot read properties of undefined (reading 'set').
Use Client#application to make a global command (works on all servers the bot is in with application.commands scope).
Use Guild#commands for guild specific commands
bot.on("ready", () => {
bot.application.commands.set([
// Global command data
])
})
And for guild specific command:
bot.guilds.cache.get("THE_GUILD_ID").commands.set(
[
// Guild command data
]
)

Discord bot not loading

My discord bot works properly but today something sus is happening. when i run the bot the thing is just loading and it just says
The terminal
It doesnt run the bot. Its supposed to log "Beta Pog" but its not has this happened to you?
I am using a event handler and its a simple console.log()
but its not working, I tried to restart it but it still doesnt work.
Code for the ready event
module.exports = {
name: 'ready',
once: true,
execute(bot) {
console.log(`Beta Pog`)
bot.user.setActivity('with beta testing')
},
};
I would steer clear of command handlers until you have a solid knowledge of javascript and discord.js in general.
We cannot debug your problem because we do not have the bot command handler code.
Here is how you would do this, using 1 index.js file and simply log "beta pog"
// require packages
const Discord = require("discord.js");
// initialise the bot
const bot = new Discord.Client();
bot.on("ready", () => {
console.log(`Beta Pog`);
bot.user.setActivity('with beta testing');
});
I would recommend using ; semi colons, it saves debugging nasty errors later
Also, I am unfamiliar with node ., try the long version node index.js etc. If the issue persists, try deleting the node modules folder, and doing npm install to recreate the packages in case it is caused by a corrupt package.
Here is a simple command handler, with a guide to follow

DiscordAPIError: Missing Access on createOverwrite

Developing a discord moderation bot with Discord.js
Facing error "DiscordAPIError: Missing Access"
My bot user, which has all server permissions except "Administrator", and highest.rawPosition is 18 (highest of all roles) :
user: ClientUser {
id: 'XXXXXXXXX',
bot: true,
username: 'Bot',
discriminator: '1863',
avatar: '2e8af5cccdc5cf15a0f88818dbb044e6',
lastMessageID: null,
lastMessageChannelID: null,
verified: true,
mfaEnabled: true,
_typing: Map {}
},
is trying to add this role (rawPosition is 2) :
Role {
id: 'XXXXXXXXX',
name: 'Mod',
color: 0,
hoist: false,
rawPosition: 2,
permissions: Permissions { bitfield: 37211712 },
managed: false,
mentionable: false,
deleted: false
}
as an overwrite permission to this channel :
CategoryChannel {
type: 'category',
deleted: false,
id: 'XXXXXXXXX',
name: 'Section Job',
rawPosition: 6,
parentID: null,
}
using this code :
await channel.createOverwrite(role, {
VIEW_CHANNEL: true,
READ_MESSAGES: true,
SEND_MESSAGES: true,
CONNECT: true
});
Here is the error I get :
[2020/10/06 00:52:56:427] DiscordAPIError: Missing Access
I performed a search before posting this.
Discord gives many possible explanations about this specific error, and none would fit with my issue : https://discordjs.guide/popular-topics/permissions-extended.html#missing-permissions
Your bot is missing the needed permission to execute this action in it's calculated base or final permissions (requirement changes based on the type of action you are trying to execute).
--> My bot has all permissions except "Administrator"
You provided an invalid permission number while trying to create overwrites. (The calculator on the apps page returns decimal values while the developer documentation lists the flags in hex. Make sure you are not mixing the two and don't use the hex prefix 0x where not applicable)
--> I give the exact same permissions, formatted exactly the same as another group, and it works
It is trying to execute an action on a guild member with a role higher than or equal to your bots highest role.
--> Not executing an action on a user, but on a group
It is trying to modify or assign a role that is higher than or equal to its highest role.
--> Bot highest role is 18, and added role rawPosition is 2
It is trying to add a managed role to a member.
--> As you can see it is not "managed"
It is trying to remove a managed role from a member.
--> Not trying to remove a role
It is trying to execute a forbidden action on the server owner.
--> Not editing a user, but a channel (and server owwner does not have this role)
It is trying to execute an action based on another unfulfilled factor (for example reserved for partnered guilds).
--> I don't understand this one but it couldn't be that
It is trying to execute an action on a voice channel without the VIEW_CHANNEL permission.
--> Not executing an action on a voice channel, but on a Category channel, and it has VIEW_CHANNEL permission
More information :
1/ The same command in the exact same context works with some other groups, like this one :
Role {
id: 'XXXXXXXXX',
name: 'Job',
color: 0,
hoist: false,
rawPosition: 1,
permissions: Permissions { bitfield: 37211712 },
managed: false,
mentionable: false,
deleted: false
}
2/ The same command works with "Administrator" permission assigned to the bot
3/ Of course, adding "Administrator" permission to the bot is not an option
Thanks for any help !
Ok then I found the solution thanks to discord Js community
I forgot to give my bot read permissions on that specific channel, so the bot couldn't give permissions to a channel he didn't have access to...
I just added
permissionOverwrites: [
{
id: guild.me.roles.highest,
allow: ['VIEW_CHANNEL', 'MANAGE_CHANNELS', 'MANAGE_ROLES']
}
]
to my channel creation, and it works.

Discord.js bot Custom presence with image

Currently trying to use setPresence for my bot, and I can get the name but no extra details for the 2nd line and no images.
bot.user.setPresence({
game: {
name: "Ready to brawl!",
application_id: 'the id',
details: "These sharks are ready for a fight.",
type: 0
},
assets: {
large_image: "large",
large_text: "Do not jump into that tank...",
small_image: "small",
small_text: "c!help"
},
status: "dnd"
});
So what shows up is:
My bot is on DND, shows "Playing Ready to brawl!", but nothing else. The details part doesn't show up and there's no large or small image.
I've used a custom presence application before so I assumed you needed your own discord application on the developers site, so I made one. I have the name of it the exact same as the "name: '.' " part and I have the id in the application id part. (I'm not sure if it's bad to share the ID so I excluded it.)
Before I tried using large_image and small_image as pure inputs and gave them links, but neither that nor this application one worked.
So if I'm seriously fucking something up here, help would be appreciated
It's normal, you can't use Rich Presence with a bot actually. Maybe someday Discord will allowed this.

Mention in embed

Is it possible to mention someone in an embed so that they receive a notification?
When I try this code:
message.channel.send({ embed: { fields: [
{
name: "test",
value: args[0]
}
]}});
with args[0] being a mention, the mention in the embed is well displayed (clickable, ...) but the user mentioned doesn't get pinged.
If I ping myself using the command (and mentioning myself in the argument) I'm not pinged and the message isn't displayed as usual when being mentioned (yellow background, ...) but I get my profile info if I click on the #... in the message.
Sadly you can't make a mention notify the mentioned user by using an Embed, a possible workaround is by having the mention in the message content, instead of the embed. For example:
message.channel.send(args[0], { embed: { fields: [
{
name: "test",
value: args[0]
}
]}});
This is a limitation of the Discord API itself.

Resources