message.guild.channels.cache.forEach((channel) => {
channel.overwritePermissions([
{
id: muteRole.id,
deny: ['SEND_MESSAGES', 'CONNECT', 'ADD_REACTIONS'],
},
], 'Mute role permissions');
});
This shows all hidden channels and resets all permissions in all channels.
The issue is that overwritePermissions() like it says overwrites every permission,
you can use updateOverwrite() instead
https://discord.js.org/#/docs/main/stable/class/TextChannel?scrollTo=updateOverwrite
message.channel.updateOverwrite(muteRole.id, {
SEND_MESSAGES: false
})
.then(console.log)
.catch(console.error);
Related
So this was working earlier, but after adding my guildCache map in order to hold server specific variables, it stopped working. I'm not sure where the error occurs, so I will be sending all of my code until the error point. Basically, on my guildCreate event the bot would normally send an image and text to the server owner, but all of a sudden my working code is now broken. Any thoughts?
My intents are GUILDS, GUILD_MESSAGES, DIRECT_MESSAGES
// Require the necessary modules
const config = require('./Data/config.json');
const insulter = require('insult');
require('dotenv').config();
const { Client, Collection } = require('discord.js');
// Create a new client instance
const client = new Client({ intents: 4609 }); // GUILDS, GUILD_MESSAGES, DIRECT_MESSAGES
const guildCache = new Collection(); //For saving independent server variables
// Functions
function getUserFromMention(mention) {
if (!mention) return;
if (mention.startsWith('<#') && mention.endsWith('>')) {
mention = mention.slice(2, -1);
if (mention.startsWith('!')) {
mention = mention.slice(1);
}
return client.users.cache.get(mention);
}
}
// --------------- BOT EVENTS -----------------
client.once('ready', () => {
console.log(`[Client] Logged in as ${client.user.tag}!`);
client.user.setActivity('you cry.', {
type: 'WATCHING'
});
// Map servers to cache for variables (also done on server join and leave)
client.guilds.cache.forEach(guild => {
guildCache.set(guild.id, {
bullyTarget: undefined,
lastInsultGenerated: undefined
});
});
console.log(guildCache);
console.log('');
});;
// On join server
client.on('guildCreate', async (guild) => {
console.log(`[Client]: Joined \"${guild.name}\"!`);
guildCache.set(guild.id, {
bullyTarget: undefined,
lastInsultGenerated: undefined
});
console.log(guildCache);
console.log('');
await client.users.cache.get(guild.ownerId).send({
content: 'You\'ll ***regret*** adding me.',
files: [{
attachment: 'src/Data/trollge.jpg',
name: 'trollge.jpg'
}]
})
.then(console.log('[Client]: Sent join message to server owner :D\n'))
.catch(console.error);
});
This is because the owner isn't in the bot's cache. You should use UserManager.fetch (on client.users)
(await client.users.fetch(guild.ownerId)).send({
content: 'You\'ll ***regret*** adding me.',
files: [{
attachment: 'src/Data/trollge.jpg',
name: 'trollge.jpg'
}]
})
You can use the Guild.fetchOwner() method to also access their GuildMember info (roles, nickname, etc.)
const owner = await guild.fetchOwner()
owner.send({
content: 'You\'ll ***regret*** adding me.',
files: [{
attachment: 'src/Data/trollge.jpg',
name: 'trollge.jpg'
}]
})
I have some code that gives my bot a status and I want it to clear with the use of a command. I am able to change the status, but I can't clear it.
Here's the code that I use to give the bot it's status:
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
targetGuild = client.guilds.cache.get('729676078599110776')
client.user.setPresence({
status: 'online',
activity: {
name: `${targetGuild.memberCount} members | !c help`,
type: "WATCHING"
}
});
});
I've tried clearing it by setting the presence without adding the status itself, but that seems to just leave it the same.
client.user.setPresence({
status: 'online'
});
Yes, the client.user.setPresence({ activity: null }) will clear the status, and if you want to log out of the bot so it's offline, you can do client.destroy()
I'm actually doing a command to start a "conversation" with a player and take responses he give me. For doing that, I've the plan to use a temporary channel. I don't find a complet way to create a channel. I saw, that we have to create the channel, and after modifie it to adjust as we want. So I have this code :
m.guild.createChannel(`Candidature-${m.author.username}`, 'text', [{
type: 'role',
id: '605021521467146279',
permission: 0x400
}])
with this error :
(node:1904) DeprecationWarning: Guild#createChannel: Create channels with an options object instead of separate parameters
and I don't find real documentation about options object. Can I have some information about how it's work, and some link to learn more ?
Thanks for your help.
I can see the confusion here as the way channels are now created have been altered and here is how to create them: (var name = "blah" isn't needed but cleans it up a bit)
var name = `ticket-${numbers}`;
message.guild.createChannel(name, { type: "text" })
And to do the channel permissions you want to use .then like this:
message.guild.createChannel(name, { type: "text" }).then(
(chan) => {
chan.overwritePermissions(message.guild.roles.find('name', '#everyone'), {
'VIEW_CHANNEL': false
})
You can change the role or change it to other things such as message.author.id or mentioned users etc.
Hope this helps!
Thanks for your answers. I have do this :
m.guild.createChannel(
`Candidature-${m.author.username}`, {
type: 'text',
topic: `Salon de candidature créé par ${m.author.username} | Id du joueur : ${m.author.id}`,
parent: idCategorie,
permissionOverwrites: [{
id: m.guild.id,
deny: ['VIEW_CHANNEL'],
},
{
id: m.author.id,
allow: ['VIEW_CHANNEL'],
}
]
})
.then((chan) => {
console.log("Channel create");
});
With those links :
https://discord.js.org/#/docs/main/stable/typedef/ChannelData
https://discordjs.guide/popular-topics/permissions.html#roles-as-bot-permissions
It's creating a channel with a name, a topic, and a categorie as parent. Only the plyaer itself and administrator can see the channel.
When sending emails through SendGrid's Node mail client ("#sendgrid/mail": "^6.4.0") we are adding some custom_args to the JSON submitted and all of them are text values. The webhooks for processed, delivered, open, and click events return the custom_args to us as expected. But when we receive a webhook for the bounce event the custom_args are not attached.
We are submitting:
{ personalizations: [
{ to: {
email: 'recipient#example.com',
name: 'Recipient Name'
}
}
],
from:
{
email: 'sender#example.com',
name: 'Sender Name'
},
reply: {
email: 'replyto#example.com',
name: 'Reply To Name'
},
custom_args:
{ envelopeId: '4aa4f5f8-9ba4-4ec3-a6cf-3098107f498d',
messageId: '105',
eventId: '251' },
subject: 'Test Email 1234',
content:
[ { type: 'text/plain',
value:
'This is a sample email, please click here: https://example.com' },
{ type: 'text/html',
value:
'This is a sample email, please <a href=\'https://example.com\'>click here</a>' } ],
mail_settings: { sandbox_mode: { enable: false } } }```
Got an answer back from SendGrid on this one. The issue is when a mail server does a slow bounce where it takes them some time to sort out that they do not have anyone with that name locally, then they sometimes return a brand new email to the sending server and that causes SendGrid to loose all of the context that was placed in the initial email.
I'm trying to make a category on discord server using Discord Bot but I couldn't find the method or something on internet. Also I looked the "discord.js.org". Then I thought that isn't there any possibility to do that. So is there any way to make a category on discord servers?
discordjs v13 needs GUILD_CATEGORY instead of just "category"
message.guild.channels.create("Name", { type: "GUILD_CATEGORY" });
You need to use the .createChannel method and then enter „category“ as type of the channel
<guild>.createChannel("NAME OF THE CHANNEL", "category")
I would advice the usage of a promise as it adds a lot of functionality and safety to your code
guild.createChannel('new-category', {
type: 'category',
permissionsOverwrites: [{
id: guild.id,
deny: ['MANAGE_MESSAGES'],
allow: ['SEND_MESSAGES']
}]
})
.then(console.log)
.catch(console.error);
This allows you to create the channel with permissions and actually handle any errors like the channel already existing or your bot not being able to create said channel cause of its permissions assigned.
This is the proper way to do this.
Example to create channel
guild.createChannel('new-general', { type: 'text' })
.then(console.log)
.catch(console.error);
v12:
message.guild.channels.create('Category', { type: 'category' });
I have made a command code for you to use. Modify it and use it.
if(message.content === `${prefix}create-channel`) {
message.guild.createChannel('name', {
//Channel type (text || voice || category)
type: 'text',
permissionsOverwrites: [{
id: guild.id,
deny: [],
allow: ['SEND_MESSAGES']
}]
})
.catch(console.error);
}
discordjs v14 needs ChannelType.GuildCategory and the name in the options
message.guild.channels.create({ name: "Name", type: ChannelType.GuildCategory });