Removing and adding roles mute command - discord.js
I've been making this mute command, the main thing is, it's only removing the main role. I want it to remove all roles and just only mute role and when unmuted the roles back again.
Here's what I've tried:
module.exports = {
name: `jail`,
description: "this is jail command!",
execute(message, args){
const member = message.mentions.users.first();
if(member){
const memberTarget = message.guild.members.cache.get(member.id);{
if (!message.member.hasPermission("MANAGE_MESSAGES")) return message.channel.send("You cant jail person because you are not staff/co owner/owner");
}
let mainRole = message.guild.roles.cache.get(`791144820810842163` , `794825576602533898` , `791144908240060426` , `791144966474563624` , `791145298072305685` , `791145926344966185` , `791146191336505414` , `791146355552682034` , `792565793568587796` , `795357387794939904` , `795358283623432213` , `798804993468530699` , `791146747367653387`)
let muteRole = message.guild.roles.cache.find(role => role.name === 'Jailed');
if (!args[1]) {
memberTarget.roles.remove(`791144820810842163` , `794825576602533898` , `791144908240060426` , `791144966474563624` , `791145298072305685` , `791145926344966185` , `791146191336505414` , `791146355552682034` , `792565793568587796` , `795357387794939904` , `795358283623432213` , `798804993468530699` , `791146747367653387`);
memberTarget.roles.add(muteRole.id);
message.channel.send(`<#${memberTarget.user.id}> has been Jailed`);
return
}
memberTarget.roles.remove(`791144820810842163` , `794825576602533898` , `791144908240060426` , `791144966474563624` , `791145298072305685` , `791145926344966185` , `791146191336505414` , `791146355552682034` , `792565793568587796` , `795357387794939904` , `795358283623432213` , `798804993468530699` , `791146747367653387`);
memberTarget.roles.add(muteRole.id);
message.channel.send(`<#${memberTarget.user.id}> has been Jailed for ${(ms(args[1]))}`);
setTimeout(function () {
memberTarget.roles.remove(muteRole.id);
memberTarget.roles.add(`791144820810842163` , `794825576602533898` , `791144908240060426` , `791144966474563624` , `791145298072305685` , `791145926344966185` , `791146191336505414` , `791146355552682034` , `792565793568587796` , `795357387794939904` , `795358283623432213` , `798804993468530699` , `791146747367653387`);
}, ms(args[1]));
} else{
message.channel.send('Cant find that member!');
}let cachedUserRoles = {};
}
}
message.guild.roles.cache.get, memberTarget.roles.remove, and memberTarget.roles.add don't support multiple arguments. You need to add the roles into a list first then iterate over them.
const mainRoles = [`791144820810842163` , `794825576602533898` , `791144908240060426` , `791144966474563624` , `791145298072305685` , `791145926344966185` , `791146191336505414` , `791146355552682034` , `792565793568587796` , `795357387794939904` , `795358283623432213` , `798804993468530699` , `791146747367653387`];
module.exports = {
name: `jail`,
description: "this is jail command!",
execute(message, args){
const member = message.mentions.users.first();
if(member){
const memberTarget = message.guild.members.cache.get(member.id);{
if (!message.member.hasPermission("MANAGE_MESSAGES")) return message.channel.send("You cant jail person because you are not staff/co owner/owner");
}
let muteRole = message.guild.roles.cache.find(role => role.name === 'Jailed');
if (!args[1]) {
mainRoles.forEach(roleId => memberTarget.roles.remove(roleId));
memberTarget.roles.add(muteRole.id);
message.channel.send(`<#${memberTarget.user.id}> has been Jailed`);
return
}
mainRoles.forEach(roleId => memberTarget.roles.remove(roleId));
memberTarget.roles.add(muteRole.id);
message.channel.send(`<#${memberTarget.user.id}> has been Jailed for ${(ms(args[1]))}`);
setTimeout(function () {
memberTarget.roles.remove(muteRole.id);
mainRoles.forEach(roleId => memberTarget.roles.add(roleId));
}, ms(args[1]));
} else{
message.channel.send('Cant find that member!');
}let cachedUserRoles = {};
}
}
Related
Integrate smartcontract with reactjs
I want to show data in reactjs application like public variables showing in remixid enter image description here when I try to console it's showing enter image description here const contractBalance = aw ait contract.getBalance(); const goal = await contract.goal(); const admin = await contract.admin(); const minCont = await contract.minimumContribution(); const nOfCont = await contract.noOfContributors(); const deadline = await contract.deadline(); const numReq = await contract.numRequests(); const raisedAmount = await contract.raisedAmount(); const requestIndex = await contract.requests(0); console.log('data: ', ethers.utils.formatEther(contractBalance)); console.log('requestIndex > ', requestIndex); console.log("minCont > " , minCont); console.log("numReq > " , numReq); console.log("raisedAmount > " , raisedAmount); console.log("nOfCont > " , nOfCont); console.log("admin > " , admin); console.log("deadline > " , deadline); please help! thanks
Because numbers in solidity are treated as BigNumbers. The most simple way to convert them is by casting them to string: console.log("minCont > " , minCont.toString());
Economy leaderboard command: undefined
I am making a discord economy/currency bot, and this is the leaderboard command. It works, but whenever I run the command !leaderboard, I don't get any of the user's tags, I just get the undefined#0000. I would like my leaderboard command to show the users with the highest amount of currency. const { MessageEmbed } = require('discord.js'); const db = require('quick.db'); module.exports = { name: "leaderboard", description: 'server\'s $ leaderboard', aliases: ['lb'], } module.exports.run = async (message) => { let money = db.all().filter(data => data.ID.startsWith(`money_`)).sort((a, b) => b.data - a.data); if (!money.length) { let noEmbed = new MessageEmbed() .setAuthor(message.member.displayName, message.author.displayAvatarURL()) .setColor("BLUE") .setFooter("No leaderboard") return message.channel.send(noEmbed) }; money.length = 10; var finalLb = ""; for (var i in money) { let currency1; let fetched = await db.fetch(`currency_${message.guild.id}`); if (fetched == null) { currency1 = '馃幈' } else { currency1 = fetched } if (money[i].data === null) money[i].data = 0 finalLb += `**${money.indexOf(money[i]) + 1}. ${message.guild.members.cache.get(money[i].ID.split('_')[1]) ? message.guild.members.cache.get(money[i].ID.split('_')[1]).tag : "undefined#0000"}** - ${money[i].data} ${currency1}\n`; }; const embed = new MessageEmbed() .setTitle(message.guild.name) .setColor("BLUE") .setDescription(finalLb) .setTimestamp() .setFooter('Command: !help for currency commands') message.channel.send(embed); }
Try following code: let money = db.all().filter(data => data.ID.startsWith(`money_${message.guild.id}`)).sort((a, b) => b.data - a.data) money.length = 10; var finalLb = ""; for (var i in money) { finalLb += `**${money.indexOf(money[i])+1}. ${client.users.cache.get(money[i].ID.split('_')[1]) ? client.users.cache.get(money[i].ID.split('_')[1]).tag : "Unknown User#0000"}** - ${money[i].data}\n`; } const embed = new Discord.MessageEmbed() .setAuthor(`Global Coin Leaderboard!`, message.guild.iconURL()) .setColor("#7289da") .setDescription(finalLb) .setFooter(client.user.tag, client.user.displayAvatarURL()) .setTimestamp() message.channel.send(embed); I personally use above code for my bot and it works pretty well for me.
Try putting the client.login('token') at the bottom of your code. Maybe the bot can't find the user tag's because of that?
Welcome message embed Discord.js
I try to do welcome message embed with avatar and its say to my TypeError: guildMember.displayAvatarURL is not a function client.on('guildMemberAdd' , guildMember =>{ let welcomeRole = guildMember.guild.roles.cache.find(r => r.id === "778565734217416711") const embed = new Discord.MessageEmbed() guildMember.roles.add(welcomeRole); guildMember.guild.channels.cache.get('802194812521939006').send(embed) embed.setTitle(`<#${guildMember.user.id}> 讘专讜讱 讛讘讗`) embed.setDescription(`<#${guildMember.user.id}> 讘专讜讱 讛讘讗 诇砖专转 讛诪讟讜专祝 讛讝讛`) embed.setThumbnail(guildMember.displayAvatarURL()) });
You cannot display the avatar of a GuildMember object, but would first have to convert it to a User object. Final Code client.on('guildMemberAdd' , guildMember =>{ let welcomeRole = guildMember.guild.roles.cache.find(r => r.id === "778565734217416711") const embed = new Discord.MessageEmbed() guildMember.roles.add(welcomeRole); guildMember.guild.channels.cache.get('802194812521939006').send(embed) embed.setTitle(`<#${guildMember.user.id}> 讘专讜讱 讛讘讗`) embed.setDescription(`<#${guildMember.user.id}> 讘专讜讱 讛讘讗 诇砖专转 讛诪讟讜专祝 讛讝讛`) embed.setThumbnail(guildMember.user.displayAvatarURL()) });
Adapting Bayesian logistic regression script to my data
I'm looking to run a hierarchical logistic regression in a Bayesian framework, but am having trouble adapting codes for my data. I have the great book "Doing Bayesian Data Analysis", but I'm not sure how to modify the script the author provided (will paste below) to rerun the analysis on my thesis data. Specifically, I have the following questions: How do I add more terms to this model? I had 5 predictors in my thesis, and this model only has 2 How do I make it hierarchical/include multiple steps or blocks? How do I add interaction terms among my predictors? I believe this script is set up for metric predictors (the book's example used height and weight data); If I am running a mixture of metric and nominal independent variables, how do I need to adapt it? any help on any of these questions would be wonderful. # Jags-Ydich-XmetMulti-Mlogistic.R # Accompanies the book: # Kruschke, J. K. (2015). Doing Bayesian Data Analysis, Second Edition: # A Tutorial with R, JAGS, and Stan. Academic Press / Elsevier. source("DBDA2E-utilities.R") #=============================================================================== genMCMC = function( data , xName="x" , yName="y" , numSavedSteps=10000 , thinSteps=1 , saveName=NULL , runjagsMethod=runjagsMethodDefault , nChains=nChainsDefault ) { require(runjags) #----------------------------------------------------------------------------- # THE DATA. y = data[,yName] x = as.matrix(data[,xName],ncol=length(xName)) # Do some checking that data make sense: if ( any( !is.finite(y) ) ) { stop("All y values must be finite.") } if ( any( !is.finite(x) ) ) { stop("All x values must be finite.") } cat("\nCORRELATION MATRIX OF PREDICTORS:\n ") show( round(cor(x),3) ) cat("\n") flush.console() # Specify the data in a list, for later shipment to JAGS: dataList = list( x = x , y = y , Nx = dim(x)[2] , Ntotal = dim(x)[1] ) #----------------------------------------------------------------------------- # THE MODEL. modelString = " # Standardize the data: data { for ( j in 1:Nx ) { xm[j] <- mean(x[,j]) xsd[j] <- sd(x[,j]) for ( i in 1:Ntotal ) { zx[i,j] <- ( x[i,j] - xm[j] ) / xsd[j] } } } # Specify the model for standardized data: model { for ( i in 1:Ntotal ) { # In JAGS, ilogit is logistic: y[i] ~ dbern( ilogit( zbeta0 + sum( zbeta[1:Nx] * zx[i,1:Nx] ) ) ) } # Priors vague on standardized scale: zbeta0 ~ dnorm( 0 , 1/2^2 ) for ( j in 1:Nx ) { zbeta[j] ~ dnorm( 0 , 1/2^2 ) } # Transform to original scale: beta[1:Nx] <- zbeta[1:Nx] / xsd[1:Nx] beta0 <- zbeta0 - sum( zbeta[1:Nx] * xm[1:Nx] / xsd[1:Nx] ) } " # close quote for modelString # Write out modelString to a text file writeLines( modelString , con="TEMPmodel.txt" ) #----------------------------------------------------------------------------- # INTIALIZE THE CHAINS. # Let JAGS do it... #----------------------------------------------------------------------------- # RUN THE CHAINS parameters = c( "beta0" , "beta" , "zbeta0" , "zbeta" ) adaptSteps = 500 # Number of steps to "tune" the samplers burnInSteps = 1000 runJagsOut <- run.jags( method=runjagsMethod , model="TEMPmodel.txt" , monitor=parameters , data=dataList , #inits=initsList , n.chains=nChains , adapt=adaptSteps , burnin=burnInSteps , sample=ceiling(numSavedSteps/nChains) , thin=thinSteps , summarise=FALSE , plots=FALSE ) codaSamples = as.mcmc.list( runJagsOut ) # resulting codaSamples object has these indices: # codaSamples[[ chainIdx ]][ stepIdx , paramIdx ] if ( !is.null(saveName) ) { save( codaSamples , file=paste(saveName,"Mcmc.Rdata",sep="") ) } return( codaSamples ) } # end function #=============================================================================== smryMCMC = function( codaSamples , saveName=NULL ) { summaryInfo = NULL mcmcMat = as.matrix(codaSamples) paramName = colnames(mcmcMat) for ( pName in paramName ) { summaryInfo = rbind( summaryInfo , summarizePost( mcmcMat[,pName] ) ) } rownames(summaryInfo) = paramName if ( !is.null(saveName) ) { write.csv( summaryInfo , file=paste(saveName,"SummaryInfo.csv",sep="") ) } return( summaryInfo ) } #=============================================================================== plotMCMC = function( codaSamples , data , xName="x" , yName="y" , showCurve=FALSE , pairsPlot=FALSE , saveName=NULL , saveType="jpg" ) { # showCurve is TRUE or FALSE and indicates whether the posterior should # be displayed as a histogram (by default) or by an approximate curve. # pairsPlot is TRUE or FALSE and indicates whether scatterplots of pairs # of parameters should be displayed. #----------------------------------------------------------------------------- y = data[,yName] x = as.matrix(data[,xName]) mcmcMat = as.matrix(codaSamples,chains=TRUE) chainLength = NROW( mcmcMat ) zbeta0 = mcmcMat[,"zbeta0"] zbeta = mcmcMat[,grep("^zbeta$|^zbeta\\[",colnames(mcmcMat))] if ( ncol(x)==1 ) { zbeta = matrix( zbeta , ncol=1 ) } beta0 = mcmcMat[,"beta0"] beta = mcmcMat[,grep("^beta$|^beta\\[",colnames(mcmcMat))] if ( ncol(x)==1 ) { beta = matrix( beta , ncol=1 ) } #----------------------------------------------------------------------------- if ( pairsPlot ) { # Plot the parameters pairwise, to see correlations: openGraph() nPtToPlot = 1000 plotIdx = floor(seq(1,chainLength,by=chainLength/nPtToPlot)) panel.cor = function(x, y, digits=2, prefix="", cex.cor, ...) { usr = par("usr"); on.exit(par(usr)) par(usr = c(0, 1, 0, 1)) r = (cor(x, y)) txt = format(c(r, 0.123456789), digits=digits)[1] txt = paste(prefix, txt, sep="") if(missing(cex.cor)) cex.cor <- 0.8/strwidth(txt) text(0.5, 0.5, txt, cex=1.5 ) # was cex=cex.cor*r } pairs( cbind( beta0 , beta )[plotIdx,] , labels=c( "beta[0]" , paste0("beta[",1:ncol(beta),"]\n",xName) ) , lower.panel=panel.cor , col="skyblue" ) if ( !is.null(saveName) ) { saveGraph( file=paste(saveName,"PostPairs",sep=""), type=saveType) } } #----------------------------------------------------------------------------- # Data with posterior predictive: # If only 1 predictor: if ( ncol(x)==1 ) { openGraph(width=7,height=6) par( mar=c(3.5,3.5,2,1) , mgp=c(2.0,0.7,0) ) plot( x[,1] , y , xlab=xName[1] , ylab=yName , cex=2.0 , cex.lab=1.5 , col="black" , main="Data with Post. Pred." ) abline(h=0.5,lty="dotted") cVec = floor(seq(1,chainLength,length=30)) xWid=max(x)-min(x) xComb = seq(min(x)-0.1*xWid,max(x)+0.1*xWid,length=201) for ( cIdx in cVec ) { lines( xComb , 1/(1+exp(-(beta0[cIdx]+beta[cIdx,1]*xComb ))) , lwd=1.5 , col="skyblue" ) xInt = -beta0[cIdx]/beta[cIdx,1] arrows( xInt,0.5, xInt,-0.04, length=0.1 , col="skyblue" , lty="dashed" ) } if ( !is.null(saveName) ) { saveGraph( file=paste(saveName,"DataThresh",sep=""), type=saveType) } } # If only 2 predictors: if ( ncol(x)==2 ) { openGraph(width=7,height=7) par( mar=c(3.5,3.5,2,1) , mgp=c(2.0,0.7,0) ) plot( x[,1] , x[,2] , pch=as.character(y) , xlab=xName[1] , ylab=xName[2] , col="black" , main="Data with Post. Pred.") cVec = floor(seq(1,chainLength,length=30)) for ( cIdx in cVec ) { abline( -beta0[cIdx]/beta[cIdx,2] , -beta[cIdx,1]/beta[cIdx,2] , col="skyblue" ) } if ( !is.null(saveName) ) { saveGraph( file=paste(saveName,"DataThresh",sep=""), type=saveType) } } #----------------------------------------------------------------------------- # Marginal histograms: decideOpenGraph = function( panelCount , saveName , finished=FALSE , nRow=1 , nCol=3 ) { # If finishing a set: if ( finished==TRUE ) { if ( !is.null(saveName) ) { saveGraph( file=paste0(saveName,ceiling((panelCount-1)/(nRow*nCol))), type=saveType) } panelCount = 1 # re-set panelCount return(panelCount) } else { # If this is first panel of a graph: if ( ( panelCount %% (nRow*nCol) ) == 1 ) { # If previous graph was open, save previous one: if ( panelCount>1 & !is.null(saveName) ) { saveGraph( file=paste0(saveName,(panelCount%/%(nRow*nCol))), type=saveType) } # Open new graph openGraph(width=nCol*7.0/3,height=nRow*2.0) layout( matrix( 1:(nRow*nCol) , nrow=nRow, byrow=TRUE ) ) par( mar=c(4,4,2.5,0.5) , mgp=c(2.5,0.7,0) ) } # Increment and return panel count: panelCount = panelCount+1 return(panelCount) } } # Original scale: panelCount = 1 panelCount = decideOpenGraph( panelCount , saveName=paste0(saveName,"PostMarg") ) histInfo = plotPost( beta0 , cex.lab = 1.75 , showCurve=showCurve , xlab=bquote(beta[0]) , main="Intercept" ) for ( bIdx in 1:ncol(beta) ) { panelCount = decideOpenGraph( panelCount , saveName=paste0(saveName,"PostMarg") ) histInfo = plotPost( beta[,bIdx] , cex.lab = 1.75 , showCurve=showCurve , xlab=bquote(beta[.(bIdx)]) , main=xName[bIdx] ) } panelCount = decideOpenGraph( panelCount , finished=TRUE , saveName=paste0(saveName,"PostMarg") ) # Standardized scale: panelCount = 1 panelCount = decideOpenGraph( panelCount , saveName=paste0(saveName,"PostMargZ") ) histInfo = plotPost( zbeta0 , cex.lab = 1.75 , showCurve=showCurve , xlab=bquote(z*beta[0]) , main="Intercept" ) for ( bIdx in 1:ncol(beta) ) { panelCount = decideOpenGraph( panelCount , saveName=paste0(saveName,"PostMargZ") ) histInfo = plotPost( zbeta[,bIdx] , cex.lab = 1.75 , showCurve=showCurve , xlab=bquote(z*beta[.(bIdx)]) , main=xName[bIdx] ) } panelCount = decideOpenGraph( panelCount , finished=TRUE , saveName=paste0(saveName,"PostMargZ") ) #----------------------------------------------------------------------------- } #===============================================================================
I need a AutoRole command when somebody joins my server
I need a AutoRole command discord.js when somebody join my discord server he gets the Discord Member role. Ive tryied some code but it doesnt work. const discord = require("discord.js"); const config = require('../config.json'); module.exports.run = async (bot, message, args) => { let target = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0])); let reason = args.slice(1).join(' '); let logs = message.guild.channels.find('name', config.logsChannel); if (!message.member.hasPermission('BAN_MEMBERS')) return message.reply('you do not have permissions to use this command!s'); if (!target) return message.reply('please specify a member to ban!'); if (!reason) return message.reply('please specify a reason for this ban!'); if (!logs) return message.reply(`please create a channel called ${config.logsChannel} to log the bans!`); let embed = new discord.RichEmbed() .setColor('RANDOM') .setThumbnail(target.user.avatarURL) .addField('Banned Member', `${target.user.username} with an ID: ${target.user.id}`) .addField('Banned By', `${message.author.username} with an ID: ${message.author.id}`) .addField('Banned Time', message.createdAt) .addField('Banned At', message.channel) .addField('Banned Reason', reason) .setFooter('Banned user information', target.user.displayAvatarURL); message.channel.send(`${target.user.username} was banned by ${message.author} for ${reason}`); target.ban(reason); logs.send(embed); }; module.exports.help = { name: 'ban' }; When they join they get the Discord Member role.
You can use the guildMemberAdd event to do actions on new users. client.on("guildMemberAdd", (member) => { member.addRole('ROLE ID HERE') });