I have this code which chooses a random user and displays their name and what they won, the problem is it can also make the user who sent the giveaway message the winner and the same with bots. How can I make an exception for the msg.author?
if(msg.content.startsWith('-giveaway'))
{
const suggestion = msg.content.slice(10);
const user = msg.guild.members.random();
let embed = new Discord.RichEmbed()
.setTitle('Prize : ' + suggestion)
.addField('Host : ', msg.author)
.addField('Nyertes : ', user)
.setFooter('Verzió 1.1')
.setTimestamp()
msg.channel.send(embed);
console.log(`${user.user}`).catch(console.error);
}
You could filter out the message author from the user list before selecting a random user:
const userList = msg.guild.members.filter(user => user.id !== msg.author.id || !msg.author.bot || msg.member.roles.some(role => role.name === 'RoleName') || msg.member.roles.some(role => role.id === 'ROLE_ID'));
const user = userList.random();
Related
I am trying to make my bot send the exact message that a user sends to a specific channel (contain the embeds) but the bot sends the text but not the attachments
Here is the code
bot.on('message', message => {
if (message.author.bot) return;
if(message.channel.id == "771695635598278677") {
message.delete()
const user = message.mentions.users.first() || message.author;
let messageAttachment = message.attachments.size > 0 ? message.attachments.array()[0].url : null
const dark = new Discord.MessageEmbed()
.setColor('#000000')
.setDescription(message.content)
.setAuthor("Dark Chat", `${message.author.displayAvatarURL()}`)
.setImage((messageAttachment)) //message.attachments.first() || {}).url
.setFooter('Dark Chat', 'https://cdn.discordapp.com/attachments/564032243836780558/771614643159433226/Anonymous_emblem.svg.png')
if(isNaN(message.content)) {
message.channel.send(dark)
}
}
});
https://discord.js.org/#/docs/main/stable/class/MessageEmbed?scrollTo=setImage
.setImage(message.attachments.array().length == 0 ? null:message.attachments.first().url)
Im making my own ticket bot right now! So first of all the bot sent a embed where you can react if you want to create a ticket (When you react the bot will create a new channel in a specific category).I changed the permissions of this category so that #everyone cant see that channel.
My question is how to change the permission so that the user who reacted can write and see his ticket-channel.
My code is:
client.on('messageReactionAdd', async (reactionReaction, user) => {
const message = reactionReaction.message;
const verifyChannel = message.guild.channels.cache.get('724929149755719751');
const member = message.guild.members.cache.get(user.id);
const guild = message.guild;
if (member.user.bot) return;
if (reactionReaction.emoji.name === '🧨' && message.channel.id === verifyChannel.id) {
guild.channels.create('Factions', { type: 'text', parent: '724929049612386375' });
await reactionReaction.users.remove(member).catch(console.error);
}
});
Thank you for helping!
You can use options.permissionOverwrites[] from the GuildChannel.create(name, options) method
client.on("messageReactionAdd", async (reactionReaction, user) => {
const message = reactionReaction.message;
const verifyChannel = message.guild.channels.cache.get("724929149755719751");
const member = message.guild.members.cache.get(user.id);
const guild = message.guild;
if (member.user.bot) return;
if (
reactionReaction.emoji.name === "🧨" &&
message.channel.id === verifyChannel.id
) {
guild.channels.create("Factions", {
type: "text",
parent: "724929049612386375",
permissionOverwrites: [
{
id: user.id,
allow: ["VIEW_CHANNEL", "SEND_MESSAGES"],
},
],
});
await reactionReaction.users.remove(member).catch(console.error);
}
});
if(!args[0]) return message.channel.send("Missing Parameter: `guild`")
if(args[0] === "guild") {
const loggingChannel = message.guild.channels.cache.find(ch => ch.name === "katsu-member-logs");
const katsuCategory = "Chika Logs";
if(!loggingChannel) {
const channelName = "katsu-member-logs";
message.guild.channels.create(channelName, { parent: katsuCategory.id, topic: "Katsu Member Logs" }).then(c => {
const allUsers = message.guild.roles.cache.find(r => r.name === "#everyone")
c.updateOverwrite(allUsers, {
SEND_MESSAGES: false
})
});
} else {
await message.channel.send("Oops, it looks like `katsu-member-logs` channel already exist in this server");
}
}
}
I have this piece of code. It is working fine as it creates the channel, however, it's not creating the text category where the channel should go. I am not quite sure on how to fix this issue. Discord.JS v12.2.0
You'd need to replace this statement with the following :
const katsuCategory = "Chika Logs";
Should be :
const katsuCategory = message.guild.channels.cache.find(c => c.name === 'Chika Logs' && c.type === 'category');
You should now be able to access it's ID and create a channel using this one as a parent :)
This the code, i want to make Temp Channel if the user doesn't have any role on Let Role =
awdawdwadwadwadwadwadwadwadwadwadawdwadawdwadwadwadwadwadwadwadwadwa
music.on('voiceStateUpdate',(lama, baru) => {
var state = null;
let Role = baru.roles.find((r) => ["IRON", "BRONZE","SILVER","GOLD","PLATINUM","DIAMOND","IMMORTAL","RADIANT"].includes(r.name));
let gakada = null
const kategorikanal = '700743802574602260'
const channelid = '700743824346972231'
if(!lama.voiceChannel && !baru.voiceChannel) return;
if(!lama.voiceChannel && baru.voiceChannel) {state = "join"}
else if(lama.voiceChannel && !baru.voiceChannel) {state = "leave"}
else if(lama.voiceChannel.id !== baru.voiceChannel.id) {state = "move"}
else if(lama.voiceChannel.id == baru.voiceChannel.id) return;
console.log(state);
//!baru.member.roles.has(allowedRole)
//if(Role === null) return; console.log("ada masalah ni ga punya role orangnya")
if(Role === null) return; console.log("ada masalah ni ga punya role orangnya")
if(baru.voiceChannelID === channelid && baru.roles.has !== Role) {
// console.log(Role)
//console.log(Role.name)
// const Role = baru.guild.roles.get("724997095236304987");
baru.guild
.createChannel(`${Role.name} | ${baru.user.username}`,"voice")
.then(tempChannel => {
tempChannel.overwritePermissions(baru.guild.defaultRole.id, {
CONNECT: false,
})
tempChannel.overwritePermissions(Role.id, {
CONNECT: true
})
tempChannel.setParent(kategorikanal);
baru.setVoiceChannel(tempChannel.id);
tempChannel.setUserLimit("5");
})
.catch(console.error)
}
if(lama.voiceChannelID) {
console.log(lama.displayName + ' gabisabgo hrus ada rank ranked ');
let Role = baru.roles.find((r) => ["IRON", "BRONZE","SILVER","GOLD","PLATINUM","DIAMOND","IMMORTAL","RADIANT"].includes(r.name));
const voicelama = lama.guild.channels.get(lama.voiceChannelID);
if(voicelama.name.startsWith(`${Role.name} | ${baru.user.username}`)){
let sawadikap = `**${baru.user.username}'s**` + " **Team**"
var koko = new Discord.RichEmbed()
.setColor("#FF4654")
.setThumbnail(`${baru.user.avatarURL}`)
.addField('**Good Game Well Played**',`${sawadikap}`)
.setFooter("#Valorant Indonesia Community." , 'https://i.imgur.com/yPWqxxu.png')
voicelama.delete()
.then(function() {
music.channels.get('725080861392896101').send(koko)
})
.catch(console.error);
}
}
})
This project for my private server, please help me to solve this problem. Thanks if u can help me.
If the person don't have any role it will set the name to "No roles"
Role ? Role.name : "No roles"
And the id of the role you want to give the permissions you can change to the user
tempChannel.overwritePermissions(Role ? Role.id : baru.id,{ ...
I am trying to make a system of giving role with a reaction, the problem is that when I go to another message (in another category) and I react with the same emoji that I put in the message to react, this gives the role...
msg.guild.fetchMembers().then(fetchedGuild => {
const totalOnline = fetchedGuild.members.filter(member => member.presence.status === "online");
const channel = client.channels.find('welcome', '👋bienvenido')
client.on('messageReactionAdd', (reaction, user) => {
let limit = (`${totalOnline.size}`);
if(message.channel.type == "text" && message.channel.name.toLowerCase() == "👋bienvenido")
{
if (reaction.emoji.name == '💻')
{
const guildMember = reaction.message.guild.members.get(user.id);
var role = message.guild.roles.find(role => role.name === "💻Programador🖱️");
guildMember.addRole(role);
}
};
});
client.on('messageReactionRemove', (reaction, user) => {
const channel = client.channels.find(c => c.name === '👋bienvenido');
const id = channel ? channel.id : null;
if(reaction.emoji.name == '💻' && id === "681933993092055053"){
const guildMember = reaction.message.guild.members.get(user.id);
var role = message.guild.roles.find(role => role.name === "💻Programador🖱️");
guildMember.removeRole(role)
}
});
});
After we talk about, I created a new code using the event raw which makes your code more readable and works in a better way!
// the event raw will receive EVERY event from <client>
client.on("raw", data => {
// just receive those two events
if (!["MESSAGE_REACTION_REMOVE", "MESSAGE_REACTION_ADD"].includes(data.t)) return;
// fetch the guild channel
const guild = client.guilds.get(data.d.guild_id);
// fetch the channel from the guild
const channel = guild.channels.get(data.d.channel_id);
// fetch who reacted the message
const reactMember = guild.members.get(data.d.user_id);
// if the reactMember is a bot, just return
if (reactMember.user.bot) return;
// just look at the channel with the ID ...
if (channel.id !== "668236577369096202") return;
// and just look at the message with the ID ...
if (data.d.message_id !== "682481892502929430") return;
// Roles to add by the emoji name
const RoleToAdd = {
"🎨": "682480577034846208",
"💻": "682480474295500803"
}
// fetch the role id by the emoji name
const roleID = RoleToAdd[data.d.emoji.name];
// if you want to put more roles to be added you can just use the emoji as the KEY and the ROLE ID as the VALUE
// "emoji": "role id"
// and if you want to work with custom emojis:
/*
const RoleToAdd = {
"emoji ID": "role ID"
}
const roleID = RoleToAdd[data.d.emoji.id];
*/
// invoke the fuction by the event name
if (data.t === "MESSAGE_REACTION_ADD") ReactionAdded();
if (data.t === "MESSAGE_REACTION_REMOVE") ReactionRemoved();
// if the member add a reaction into the message
function ReactionAdded() {
// check if the roleID exists by the emoji and if the member DOESNT have that role
if (roleID && !reactMember.roles.has(roleID)) {
// add him into the role
reactMember.addRole(roleID)
};
}
// if the member removed a reaction from the message
function ReactionRemoved() {
// check if the roleID exysts by the emoji and if the member HAS that role
if (roleID && reactMember.roles.has(roleID)) {
// remove him from the role
reactMember.removeRole(roleID);
}
}
});
// Hope this helps!