I need help for discord js v13 - javascript

my code
function kanalbackup() {
let guild = client.guilds.cache.get(ayarlar.guildID);
if (!guild) return;
if (guild) {
guild.channels.cache.filter(kanal => kanal.deleted !== true).forEach(channel => {
let permissionss = {};
let sayi = Number(0);
channel.PermissionOverwriteManager.forEach((perm) => {
let thisPermOverwrites = {};
perm.allow.toArray().forEach(p => {
thisPermOverwrites[p] = true;
});
perm.deny.toArray().forEach(p => {
thisPermOverwrites[p] = false;
});
permissionss[sayi] = {permission: perm.id == null ? guild.id : perm.id, thisPermOverwrites};
sayi++;
})
error
Channel#deleted is deprecated,
(Use node --trace-deprecation ... to show where the warning was created)
TypeError: channel.permissionOverwrites.forEach is not a function
Discord js upgrade error v12 to v13 ı need help

Basically the function channel.deleted has been removed from discord.js and you can't use it anymore. Full article on this: https://github.com/discordjs/discord.js/issues/7091. You can simply remove the filter in the channel cache to solve the problem. It also appears that you haven't created a permissionOveriteManager, and it's spelled wrong. The code would then look like the following:
function kanalbackup() {
let guild = client.guilds.cache.get(ayarlar.guildID);
if (!guild) return;
if (guild) {
guild.channels.cache.forEach(channel => {
let permissionss = {};
let sayi = Number(0);
channel.permissionOverwriteManager.create().forEach((perm) => {
let thisPermOverwrites = {};
perm.allow.toArray().forEach(p => {
thisPermOverwrites[p] = true;
});
perm.deny.toArray().forEach(p => {
thisPermOverwrites[p] = false;
});
permissionss[sayi] = {permission: perm.id == null ? guild.id : perm.id, thisPermOverwrites};
sayi++;
})

Related

TypeError: (intermediate value)._patchPlaylist is not a function

I've got error message like "TypeError: (intermediate value)._patchPlaylist is not a function" on console log. Please check out what's wrong from my script:
const playlist = new distube_1.Playlist(playlistInfo);
const fetchTheRest = async (q, fs, us = false) => {
if (queries.length) {
let results = [];
if (this.parallel) {
results = await Promise.all(queries.map(query => this.search(query)));
}
else {
for (let i = 0; i < queries.length; i++) {
results[i] = await this.search(queries[i]);
}
}
playlist.songs = results
.filter((r) => !!r)
.map(r => new distube_1.Song(r, member)._patchPlaylist(playlist));
q.addToQueue(playlist.songs, skip ? 1 : us ? 2 : -1);
}
playlist.songs.unshift(fs);
};
How I can fix it?
thanks for help me.

how to get a users roles discord.js

I want to check if a user has a role but when I try to get the user it always returns the bot user, not the wanted user. How can I go about fixing this?
Here's my code:
const member = client.guilds.cache.get(localVars.ServerID).members.cache.find((member) => {
console.log(member.username);
return member.username == localVars.username;
});
const role = client.guilds.cache.get(localVars.ServerID).roles.cache.find((role) => {
return role.name === localVars.RoleName;
});
console.log(member);
if (member.roles.cache.get(role.id)) {
localVars.ReturnValue = 1;
} else {
localVars.ReturnValue = 0;
}
Your code is a little bit overcomplicated and some things are just unneccessary / wrong, e.g. that you call return in the find() and get() functions :D
You could simplify it like this:
const { guilds } = client;
const targetGuild = guilds.cache.get(localVars.ServerID);
const member = targetGuild.members.cache.find(user => user.username === localVars.username);
const role = targetGuild.roles.cache.find(role => role.name === localVars.RoleName);
if(member.roles.cache.has(role.id)) {
localVars.ReturnValue = 1
} else {
localVars.ReturnValue = 0
}

voxeet/dolby.io generating multiple conferences

I am using dolby.io
Till now I have implemented join conference, leave conference, start and stop video, start and stop recording, start and stop screen sharing. What I am facing issue is about multiple conference. I want to implement multiple conferences with unique conference IDs so that every user specified for relevant conference should join its own. I am not getting any idea from its official documentation.
here is my code
const initUI = () => {
const nameMessage = document.getElementById('name-message');
const joinButton = document.getElementById('join-btn');
const conferenceAliasInput = document.getElementById('alias-input');
const leaveButton = document.getElementById('leave-btn');
const startVideoBtn = document.getElementById('start-video-btn');
const stopVideoBtn = document.getElementById('stop-video-btn');
const startScreenShareBtn = document.getElementById('start-screenshare-btn');
const stopScreenShareBtn = document.getElementById('stop-screenshare-btn');
const startRecordingBtn = document.getElementById('start-recording-btn');
const stopRecordingBtn = document.getElementById('stop-recording-btn');
//const mute_unmute = document.getElementById('mute');
//oxeetSDK.conference.mute(VoxeetSDK.session.participant, VoxeetSDK.session.participant.isMuted);
//let isMuted = VoxeetSDK.conference.toggleMute(VoxeetSDK.session.participant);
nameMessage.innerHTML = `${randomName}`;
joinButton.disabled = false;
joinButton.onclick = () => {
let conferenceAlias = conferenceAliasInput.value;
/*
1. Create a conference room with an alias
2. Join the conference with its id
*/
VoxeetSDK.conference.create({ alias: conferenceAlias })
.then((conference) => VoxeetSDK.conference.join(conference, {}))
.then(() => {
joinButton.disabled = true;
leaveButton.disabled = false;
startVideoBtn.disabled = false;
startScreenShareBtn.disabled = false;
startRecordingBtn.disabled = false;
})
.catch((e) => console.log('Something wrong happened : ' + e))
};
leaveButton.onclick = () => {
VoxeetSDK.conference.leave()
.then(() => {
joinButton.disabled = false;
leaveButton.disabled = true;
startScreenShareBtn.disabled = true;
stopScreenShareBtn.disabled = true;
})
.catch((err) => {
console.log(err);
});
};
startVideoBtn.onclick = () => {
VoxeetSDK.conference.startVideo(VoxeetSDK.session.participant)
.then(() => {
startVideoBtn.disabled = true;
stopVideoBtn.disabled = false;
});
};
stopVideoBtn.onclick = () => {
VoxeetSDK.conference.stopVideo(VoxeetSDK.session.participant)
.then(() => {
stopVideoBtn.disabled = true;
startVideoBtn.disabled = false;
});
};
startScreenShareBtn.onclick = () => {
VoxeetSDK.conference.startScreenShare()
.then(() => {
startScreenShareBtn.disabled = true;
stopScreenShareBtn.disabled = false;
})
.catch((e) => console.log(e))
};
stopScreenShareBtn.onclick = () => {
VoxeetSDK.conference.stopScreenShare()
.then(() => {
startScreenShareBtn.disabled = false;
stopScreenShareBtn.disabled = true;
})
.catch((e) => console.log(e))
};
startRecordingBtn.onclick = () => {
let recordStatus = document.getElementById('record-status');
VoxeetSDK.recording.start()
.then(() => {
recordStatus.innerText = 'Recording...';
startRecordingBtn.disabled = true;
stopRecordingBtn.disabled = false;
})
.catch((err) => {
console.log(err);
})
};
stopRecordingBtn.onclick = () => {
let recordStatus = document.getElementById('record-status');
VoxeetSDK.recording.stop()
.then(() => {
recordStatus.innerText = '';
startRecordingBtn.disabled = false;
stopRecordingBtn.disabled = true;
})
.catch((err) => {
console.log(err);
})
};
};
const addVideoNode = (participant, stream) => {
const videoContainer = document.getElementById('video-container');
let videoNode = document.getElementById('video-' + participant.id);
if(!videoNode) {
videoNode = document.createElement('video');
videoNode.setAttribute('id', 'video-' + participant.id);
videoNode.setAttribute('controls', true);
//VoxeetSDK.conference.mute(VoxeetSDK.session.participant, VoxeetSDK.session.participant.isMuted);
//let isMuted = VoxeetSDK.conference.toggleMute(VoxeetSDK.session.participant);
//console.log(isMuted);
//videoNode.setAttribute('height', 240);
//videoNode.setAttribute('width', 720);
videoContainer.appendChild(videoNode);
videoNode.autoplay = 'autoplay';
videoNode.muted = true;
}
navigator.attachMediaStream(videoNode, stream);
};
const removeVideoNode = (participant) => {
let videoNode = document.getElementById('video-' + participant.id);
if (videoNode) {
videoNode.parentNode.removeChild(videoNode);
}
};
const addParticipantNode = (participant) => {
//const members_count++;
const participantsList = document.getElementById('participants-list');
// if the participant is the current session user, don't add himself to the list
if (participant.id === VoxeetSDK.session.participant.id) return;
// let participantNode = document.createElement('li');
// participantNode.setAttribute('id', 'participant-' + participant.id);
// participantNode.innerText = `${participant.info.name}`;
//alert(VoxeetSDK.session.participant);
//document.getElementById('members_count').innerText=participant.id;
let participantNode = document.createElement('div');
participantNode.setAttribute('class', 'tabcnt-item');
participantNode.setAttribute('id', 'participant-' + participant.id);
//document.getElementById('members_count').innerText = document.getElementById('members_count').innerText + 1;
//document.getElementById('members_count').innerText = members_count;
participantNode.innerText = `${participant.info.name}`;
const send_html = "<div class='tabcnt-item'><div class='row align-items-center'><div class='col-md-8'><div class='media'><img src='images/pp.png' alt=''><div class='media-body'><h3>'"+`${participant.info.name}`+"'</h3><p>email#dname.com</p></div></div></div><div class='col-md-4'><ul><li><a href='#'><i class='fas fa-video'></i></a></li><li><a href='#'><i class='fas fa-microphone'></i></a></li></ul></div></div></div>";
participantNode.innerHTML = send_html;
participantsList.appendChild(participantNode);
document.getElementById('members_count').innerText= $('.tab-cnt').length;
};
const removeParticipantNode = (participant) => {
let participantNode = document.getElementById('participant-' + participant.id);
if (participantNode) {
participantNode.parentNode.removeChild(participantNode);
document.getElementById('members_count').innerText= $('.tab-cnt').length;
}
};
const addScreenShareNode = (stream) => {
const screenShareContainer = document.getElementById('screenshare-container');
let screenShareNode = document.getElementById('screenshare');
if (screenShareNode) return alert('There is already a participant sharing his screen !');
screenShareNode = document.createElement('video');
screenShareNode.setAttribute('id', 'screenshare');
screenShareNode.autoplay = 'autoplay';
navigator.attachMediaStream(screenShareNode, stream);
screenShareContainer.appendChild(screenShareNode);
}
const removeScreenShareNode = () => {
let screenShareNode = document.getElementById('screenshare');
if (screenShareNode) {
screenShareNode.parentNode.removeChild(screenShareNode);
}
}
I am exhausted and tired of googling. It will be a great help if some can guide or provide direction towards more elaborative documentation. I have read each and every bit of dolby docs. Thanks for reading
When you call create() a new conference id is generated which is a guid specific for your account. You can call get_id() to find it. You can also specify an alias to help for readability when there may be multiple conferences active at any given time.
If you want to have multiple conferences, you should call create() multiple times. That is, the expectation is the typical app initializes only a single conference but there are multiple running instances each having its own conference and/or to invite others to an existing conference. For webapps, that may be a separate user session rather than a separate deployed mobile application. You may want to do some book keeping for what ids are generated for each user in your own services.
You may be looking for all of the conferences that are active on an account at any given time while testing or monitoring your deployed apps. You can use the Monitor API getConferences to get that list.
If you have additional questions, it is probably best to use Dolby.io Support for more personal answers and guidance.

How can I go about handling an error, ignoring it and continuing with the function? discord.js

I'm trying to dm all users in my private server with all my friends however some of them don't want to be dmed so they turn off their dms. Because of this, I get an error which stops the bot from continuing on to the other users. How can I skip over that user when the error is found and tell my bot to continue to dm the next user after.
heres my code
const commando = require('discord.js-commando');
const app = require('../../app.js');
const config = require('../../config.json');
const Discord = require('discord.js');
class DMallCommand extends commando.Command {
constructor(client){
super(client, {
name: `dmall`,
group: 'dms',
memberName: 'dmall',
description: 'Sends message provided to all members of the guild.',
examples: [ `${config.prefix}dmall Hey everyone! This might reach more people than a mass ping...` ]
});
}
async run(message, args){
let dmGuild = message.guild;
let role = message.mentions.roles.first();
var msg = message.content;
try {
msg = msg.substring(msg.indexOf("dmall") + 5);
} catch(error) {
console.log(error);
return;
}
if(!msg || msg.length <= 1) {
const embed = new Discord.RichEmbed()
.addField(":x: Failed to send", "Message not specified")
.addField(":eyes: Listen up!", "Every character past the command will be sent,\nand apparently there was nothing to send.");
message.channel.send({ embed: embed });
return;
}
let memberarray = dmGuild.members.array();
let membercount = memberarray.length;
let botcount = 0;
let successcount = 0;
console.log(`Responding to ${message.author.username} : Sending message to all ${membercount} members of ${dmGuild.name}.`)
for (var i = 0; i < membercount; i++) {
let member = memberarray[i];
if (member.user.bot) {
console.log(`Skipping bot with name ${member.user.username}`)
botcount++;
continue
}
let timeout = Math.floor((Math.random() * (config.wait - 0.01)) * 1000) + 10;
await sleep(timeout);
if(i == (membercount-1)) {
console.log(`Waited ${timeout}ms.\t\\/\tDMing ${member.user.username}`);
} else {
console.log(`Waited ${timeout}ms.\t|${i + 1}|\tDMing ${member.user.username}`);
}
try {
member.send(`${msg} \n #${timeout}`);
successcount++;
} catch (error) {
console.log(`Failed to send DM! ` + error)
}
}
console.log(`Sent ${successcount} ${(successcount != 1 ? `messages` : `message`)} successfully, ` +
`${botcount} ${(botcount != 1 ? `bots were` : `bot was`)} skipped.`);
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
module.exports = DMallCommand;
I understand I am not handling any errors but I am not sure how to go about this and could really use some help
Also here is my bot.js code
const Discord = require('discord.js');
const figlet = require('figlet');
const colors = require('colors');
const readline = require('readline');
const commando = require(`discord.js-commando`);
const config = require('./config.json');
const bot = new commando.Client({
commandPrefix:'£',
owner: config.id
});
const cmdsArray = [
"dmall <message>",
"dmrole <role> <message>"
];
bot.on("ready", () => {
clear();
console.log('______')
bot.user.setActivity('PRDX');
});
bot.on("error", (error) => {
bot.login(config.token);
});
bot.registry.registerGroup('dms', 'help');
bot.registry.registerDefaults();
bot.registry.registerCommandsIn(__dirname + "/commands");
if (process.env.BOT_TOKEN) bot.login(process.env.BOT_TOKEN);
else bot.login(config.token);
}
Anywhere in your code use an error event listener
client.on("error", () => { client.login(token) });
You'll want to catch the error, basically, if that error happens, you want it to just pass by and ignore the error. In Javascript this is known as try and catch. Read about it below then apply it to wherever the error is being identified.
https://www.w3schools.com/js/js_errors.asp
You can use .catch() block, member.send('Message') return a promise with succes sended message or error. So you can use
member.send('message').catch(console.error)

I cant get code to detect the beginning of a link (www or https)

currently trying to get my code to notice the beginning of a message if its "www" or "https" and then checking if they're associated with either reddit or youtube, I've tried multiple different posts (there arent very many on the discord API for javascript) so Im kinda stumpted at this point
const botconfig = require("./botconfig.json");
const Discord = require("discord.js");
const bot = new Discord.Client();
var protect = false;
const forbidenWords = ['reddit', 'youtube']
const Message = ''
bot.login(botconfig.token);
let prefix = "!";
bot.on("message", (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
if (message.content.startsWith(prefix + "protect")) {
message.channel.send("PROTECT THE KING!!!!");
protect = true;
console.log('protecc is true')
} else
if (message.content.startsWith(prefix + "stop")) {
message.channel.send("I will now stop :(");
protect = false;
}
if(protect == true && message.content.startsWith("www" || "https")){
console.log('isWebsite true')
for (var i = 0; i < forbidenWords.length; i++) {
if (message.content.includes(forbidenWords[i])) {
break;
}
}
}
});
any help on this is greatly appreciated.
Move the additional logic into a helper function.
function startsWithWebsiteToken(message) {
const tokens = ['https', 'www'];
const length = tokens.length;
for (let i = 0; i < length; i++) {
if ( message.startsWith(tokens[i]) )
return true;
}
return false;
}
if (protect === true && startsWithWebsiteToken(message.content)) {
console.log('isWebsite true');
}
You can define a custom function for this
START_TOKENS = ['https','https','www'];
function doesUrlStartWithToken(url) {
return START_TOKENS.reduce((accumulator, currentValue) => {
if (accumulator) {
return true;
}
return currentValue.startsWith(url);
}, false);
}
Alternatively, if you only need to support browser which support new URL(), it becomes easier to detect certain domains
const SPECIAL_DOMAINS = ['youtube.com', 'reddit.com']
function isSpecialDomain(url) {
const deconstructedUrl = new URL(url)
const domain = deconstructedUrl.hostname.replace('www.','');
return SPECIAL_DOMAINS.reduce((e, val) => e || domain === val, false);
}

Categories