I am trying to move the tagged user into the voice channel using the channel ID. I saw someone use .setUserChannel but it tells me that it isn't a function. Can someone tell me what I need to fix please :)
if(command === 'ping'){
message.channel.send('pong');
} else if (command === 'abuse'){
//const AbuseTown = client.channel.cache.get(760535995329282161);
const taggedUser = message.mentions.users.first();
message.channel.send(`You want to abuse: ${taggedUser.username}`);
taggedUser.setVoiceChannel('776202269569712168');
return;
}
First of all, you need the GuildMember object, not the User object. Learn more about the difference here
// change:
const taggedUser = message.mentions.users.first();
// to:
const taggedUser = message.mentions.members.first();
Second of all, GuildMember.setVoiceChannel() is an outdated function, so it won't work if you're using v12.x. Instead, use VoiceState.setChannel().
const taggedUser = message.mentions.members.first();
message.channel.send(`You want to abuse: ${taggedUser.username}`);
taggedUser.voice.setChannel('776202269569712168');
Related
I have a discord bot that I'm attempting to assign a user a role with. From some searching around, I've discovered that the code
let role = message.guild.roles.cache.get("[role_id]")
message.author.roles.add(role)
is supposed to work.
The issue is that message.author.roles doesn't exist. Is there a new way to do this for discord.js v13, or am I missing something?
As per the discord.js docs, Message#author is a User object, which doesn't have the .roles property. What you want is Message#member, which is a GuildMember and has the property you want in order to give and remove roles.
Give this a shot:
let role = message.guild.roles.cache.get("[role_id]")
message.member.roles.add(role)
I use another method and it works as good as this, try it out
let role = message.guild.roles.cache.find((role) => role.name === "[role name here]")
message.member.roles.add(role)
const mention = (await message.mentions.members.first()) || message.guild.members.cache.get(args[0]) || message.guild.members.cache.find((r) => r.user.username.toLowerCase().includes() === args.join(" ").toLocaleLowerCase()) || message.guild.members.cache.find((r) => r.displayName.toLowerCase().includes() === args.join(" ").toLocaleLowerCase()); // get member on mention
const role = message.mentions.roles.first(); // get role on mention
await mention.roles.add(role)
{prefix} {command} {mention a user} {mention a role}
Don't forget, this is in async function
So when trying to make my Discord.js bot display an User Avatar, it works with other bots but not with actual users, I have this problem on all commands that use user.avatarURL
This is the code I am using
const user = message.mentions.users.first();
if(message.content.toLowerCase().startsWith(`${prefix}av`)){
let member = message.mentions.members.first();
if(member){
const emb=new Discord.MessageEmbed()
emb.setAuthor(`${user.username}'s avatar`, user.avatarURL())
emb.setImage(user.avatarURL());
message.channel.send(emb)
}
else{
message.channel.send("Sorry none found with that name")
}
You should use displayAvatarURL instead, with the optional dynamic option.
emb.setAuthor(`Text`, user.displayAvatarURL({ dynamic: true }));
https://discord.js.org/#/docs/main/stable/class/User?scrollTo=displayAvatarURL
is there any way to put the user who created the channel in .setAuthor? I searched in https://discord.js.org/#/docs/main/stable/class/GuildChannel but found nothing
client.on("channelCreate", function(channel) {
const logchannel = channel.guild.channels.cache.find(ch => ch.name === "logchannel")
if (!logchannel) return
const embed = new Discord.MessageEmbed()
.setTitle("Channel created)
.setDescription(`Channel <#${channel.id}> has created.`)
.setTimestamp()
.setAuthor(//user who created the channel)
logchannel.send(embed)
})
I think it's best to use the AuditLogs, you may want to take a look at it.
so I am trying to make a ROSTER command. The command is $roster add/remove #user RANK. This command basically should edit a previous bot's message (roster) and add a user to the roster to the RANK in the command... This is my code so far, but I haven't managed to make the roster message and the editing part of it and the RANK system. If someone could help that would be very amazing!
//ROOSTER COMMAND
client.on('message', async message => {
if (message.content.startsWith(prefix + "roster")) {
if (!message.member.hasPermission('ADMINISTRATOR')) return message.channel.send('You do not have that permission! :x:').then(message.react(':x:'))
const args = message.content.slice(prefix.length + 7).split(/ +/)
let uReply = args[0];
const user = message.mentions.members.first()
if(!uReply) message.channel.send("Please use `add` or `remove`.")
if(uReply === 'add') {
if(!user) return message.channel.send("Please make sure to provide which user you would like to add...")
message.channel.send(`you are adding **${user.displayName}** from the roster.`)
} else if(uReply === 'remove') {
if(!user) return message.channel.send("Please make sure to provide which user you would like to add...")
message.channel.send(`you are removing **${user.displayName}** from the roster.`)
}
}})
Sounds like the .edit() method is what you want.
Example from the docs:
// Update the content of a message
message.edit('This is my new content!')
.then(msg => console.log(`Updated the content of a message to ${msg.content}`))
.catch(console.error);
To edit your bots previous message, you need to have a reference of the message you want to edit. The returned reference is a promise so do not forget to use await keyword. you can then use .edit() function on the reference to update you msg.
const msgRef = await msg.channel.send("Hello");
msgRef.edit("Bye");
const Discord = require("discord.js");
const prefix = ("d");
const client = new Discord.Client ();
client.on("ready", async () => {
console.log(`${client.user.username} is now working online!`);
});
client.on("message", message => {
if(message.author.bot) return;
if(message.channel.type === "dm") return;
let messageArray = message.content.split(" ");
let command = messageArray[0];
let args = messageArray.slice(1);
if(!command.startsWith(prefix)) return;
});
client.login("MY TOKEN");
When I try doing the command: "dhelp" that I've made and coded for example, it doesn't work. Why is this? People have said that I need a command handler and I think it's done but don't why it is still not working, why is this? Please help me, I really need help right now.
Well, to start off, it doesn't actually look like your code does anything regardless of what the value of command is. Perhaps using if/else statements would be a good place to start.
if (command === "help") {
/* some code here */
}
where /* some code here */ is the code for your bot.