Changing nickname of bot with a command [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I would like to make changes to my bot's name with a command like !Changenick nick - by 'nick' I mean the new bot's name. Could you guys help me? I just want bot to change username when someone writes !Changenick for example:
!changenick Freshname
bot changes his own name to Freshname

If you want to change a users nickname you need a GuildMember obj. You can apply this to the bot by searching the guild's member prop for the bots id. The following line will allow you to change the bot's username given a Message obj.
message.guild.me.setNickname('NICKNAME'); updated based on suggestion from #slothiful
If you need further assistance with how to create the entire command, reference https://discordjs.guide/ and https://discord.js.org/#/docs/
Update 1: I am having a hard time understanding your desired implementation with the examples you have provided.
Let's assume you want a command something like this: !changenick <#user> <nickname>
In this case, I would reference this. It explains how you can parse mentions. On to the actual question of changing the nickname, you can change the nickname of any user
(you will get this user via the mention) by using message.guild.members.find(user => user.id === mentionUser.id).setNickname('NICKNAME')
Update 2: I now see what you were getting at. My apologies. You do not need to restart the bot to allow the nickname to update. I have tested it.
The below code changes the bots nickname every 10 seconds.
const Discord = require('discord.js');
const Client = new Discord.Client();
Client.on('ready', () => {
let value = 0;
setInterval(() => {
Client.guilds.find(guild => guild.id === 'GUILD_ID').me.setNickname(value++);
}, 10000);
});
Client.login('TOKEN');
The important bit is
Client.guilds.find(guild => guild.id === 'GUILD_ID').me.setNickname('NICKNAME');
Edit: If this answers your question, mark the answer as accepted.

Related

I want to make a Discord meme bot using JavaScript [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have recently made a Python Discord bot and I want to built the same with JavaScript. I am totally new in this language and I don't know how I will add the meme command in.
in the Python version, I used a website heroukuapp to get memes from subreddit.
Here's how I made it in Python-
if message.content == 'Show me some memes':
content = get("https://meme-api.herokuapp.com/gimme").text
data = json.loads(content,)
meme = discord.Embed(title=f"{data['title']}", Color = discord.Color.random()).set_image(url=f"{data['url']}")
await message.channel.send("MEMEY.....MEMEY.....MEMEY......\n")
await message.channel.send(embed=meme)
I want to use the same website for displaying memes in the JS bot (in embeds form). I have tried many APIs and seen many videos, but still I ccouldnt use them.
Till now, this is what I have done in JavaScript-
case "Show me some memes":
message.channel.send("MEMEY.....MEMEY.....MEMEY......\n")
break;
Can anyone solve my query?
Thanks for viewing my post.
You may use got an Node.js based HTTPS request library to request the API and further parse the response and use the things you need from the body ( alternatives - node-fetch ( previously snekfetch - ESM module ))
Here's an example:
const got = require("got");
const { MessageEmbed } = require("discord.js");
got("https://meme-api.herokuapp.com/gimme").then( (response) => {
const data = JSON.parse(response.body);
let meme = new MessageEmbed
.setTitle(`${data['title']}`);
.setColor("RANDOM");
.setImage(`${data['url']}`)
message.channel.send({ content: "MEMEY..MEMEY...MEMEY...", embeds: [meme]});
});
This is specifically for discord.js v13 if you're on any version that's below 13 you may directly pass the embed object like so:
message.channel.send(meme);

Custom status with guild number [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have another discord.js query which involves custom statuses. I want my bot's custom status to be "Being Used In # Guilds/Servers" where # is the number of guilds the bot will be in.
Note that by "custom status" I don't mean a Playing status:
I mean a custom status (without "Playing"):
(Yes, that is OG Clyde, because I had my account since the Christmas Vacation 2020.)
So some answers say that Discord.js V12 only has Playing Statuses, not Custom Statuses. Now I had a conversation with #jabaa (in the comments) which said that I should share my own research and code, or else people will downvote. But I cannot share, because I don't know which code to use. I know one to display memberCount in the status, but not guild numbers.
Alright, I am using this in my bot too: here is the code
//...
client.on('ready', () => {
//...
client.user.setActivity('othertext' + client.guilds.cache.size, {type : 'PLAYING'})
}
client.on('guildCreate', guild => {
//same code as 'ready'
})
client.on('guildDelete', guild => {
//also the same code as 'ready'
})
Now this was from my human memory but this is a start, just modify it with any errors you may have, hopefully there are none.
NOTE: If you are just putting the number of guilds, for some reason, make sure the add the '' after the client.guilds.cache.size, otherwise you will get an error saying it got a number but expected string
DJS does not currently have support for Custom Statuses the same way users do, so this is not possible at this time.
As you can see here,
Bots cannot set a CUSTOM_STATUS, it is only for custom statuses
received from users
ClientUser.setStatus() takes a PresenceData type as an argument, which in turn has an object activity and its property type that can be either PLAYING, STREAMING, LISTENING, WATCHING or COMPETING

How can I command my bot to lock the current channel? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I want my bot to be able to lock down a channel when I use a command. This is my current code:
if (command === 'lock') {
guild.members.cache.find.permissions.remove('SEND_MESSAGES');
}
However, it's not working, and I'm not sure how to fix it.
The .updateOverwrite() method will update an existing permission setting or create one if none exists. This is how you use it:
.updateOverwrite(userOrRole, options, [reason])
Role: RoleResolveable (role object) or Snowflake,
User: UserResolveble (user object) or Snowflake
Reason: String (optional)
Example of how you could use this:
// First find the role we want to overwrite permissions for
const role = message.guild.roles.cache.find(r => r.name === "#everyone");
message.channel.updateOverwrite(role, { SEND_MESSAGES: false }, `Overwrite permissions`)
.then(() => console.log("Permissions overwritten."))
.catch(error => {
console.log("Oh no! Something went wrong! " + error.message);
});
If you want to overwrite all channels, simply map all channels in the guild and use channel.updateOverwrite(). You want to use updateOverwrite since overwritePermissions will replace all current permissions and replace it with the one you want to add or update.
First of all, you need message.channel to get the channel the command is sent in. Then, you can use channel.updateOverwrite():
// fun fact, the #everyone role shares the same id as the guild
message.channel.updateOverwrite(message.guild.id, {
SEND_MESSAGES: false // cannot send messages
}, 'Channel Lockdown')
.then(console.log)
.catch(consol.error); // handle any errors
The updateOverwrite() function accepts three parameters. First, a User or Role resolvable (typically the ID or object). In this case, I used message.guild.id, which is the ID of the #everyone role.
Then, the overwrite options. You can use any Permission Flag (for example, ADD_REACTIONS, and VIEW_CHANNEL) followed by false for denied, null for unset, and true for allowed.
Then finally, you can provide a reason which is what will appear in the audit logs!
You can do something similarly if you want to lockdown every channel:
// iterate a function over every channel in the guild
message.guild.channels.cache.forEach((channel) => {
message.channel.updateOverwrite(message.guild.id, {
SEND_MESSAGES: false
}, 'Channel Lockdown')
.then(console.log)
.catch(consol.error);
});
This will work the same with v11.x, just replace updateOverwrite() with overwritePermissions()

Get document collections in Firestore [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
this is my firebase database
- conversations (collection)
-- xxx (document)
--- users (collection)
---- xxx (document)
I want to list all the conversations and its users
this.db.collection('conversations').get().then(querySnapshot => {
querySnapshot.docs.forEach(doc => {
console.log(doc.collection('users').get())
});
});
I´m getting doc.collection is not a function
update: this is what I have after getting the id and making a new query. now the question is. is this performant?
this.db.collection('conversations').get().then(conversationsQuerySnapshot => {
conversationsQuerySnapshot.docs.forEach(doc => {
this.db.collection('conversations').doc(doc.id).collection('users').get().then(usersQuerySnapshot => {
usersQuerySnapshot.docs.forEach(doc => {
console.table(doc.data());
});
});
});
});
You're looking for doc.ref.collection('users'), since you need go get from the DocumentSnapshot to its DocumentReference through doc.ref.
Note that I find it easiest to spot such mistakes by simply following the types. Your querySnapshot is a QuerySnapshot, which means that your doc is a QueryDocumentSnapshot. Since QueryDocumentSnapshot doesn't have a collection method, it's easier to figure out what's going wrong.
you would call it: db.collection('conversations').doc({docID}).collection('users')
Your current query is set up to look through every conversation and then get every user in each of those. Plus the second part (getting the users) has no base document to pull from, which is why you're seeing an error.
I recommend watching this video

userId.getUserById is not a function [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
When a user click's on a username on the list below, it's meant to open up the add user page with the name's of the user in the fields.
I get this error message:
Here's the code in the manage users page:
componentWillMount: function () {
var userId = this.props.params.id; // from the path /user:id
if (userId) {
this.setState({ user: userId.getUserById(userId) });
}
},
Here's the code in the userApi:
getUserById: function(id) {
var user = _.find(users, {id: id});
return _clone(user);
},
I am new to StackOverflow and programming, so if this post doesn't meet the community's guidelines, please guide me on how to better make use this platform so I can further my learning progression.
Thanks,
Rickie
Using the userId variable you can't call your API. Since getUserById is from your API you must call the method from there.
userApi.getUserById(userId);

Categories

Resources