I want to add a new command to my bot, a command that will send the log messages of the guild to the mentioned channel.
Use:
!logs #channel
I also want it to be a specific type of log to a different channel.
Use:
!logs ban-msg #channel
!logs delete-msg #channel
I don't need the second option but I do want it.
The question asked requires a long study; Discord does not provide any simple solution. To make such functionality you need:
Create a database in which event data will be recorded ("_id","event","channel_id")
Next, you can handle discord Events to determine the event, then pass it through the database, see if the channel is set in the database for posting this event, if so - then send a specific embed to the specified channel.
Related
So lets say a Discord bot is a member of server A and server B, and there is a custom emoji being hosted on server A. How do I get the bot to send the emoji on server B? I have seen bots such as MEE6 that can send custom emojis in DMs, so this surely must be possible.
I have tried both this:
message.channel.send('Test <:[emoji_name]:[id]>');
and this:
message.channel.send(`Test ${client.guilds.cache.get('[server_id]').emojis.cache.first()}`);
I used .first() since there is only one emoji in the server.
Both of these do not work. The emoji will appear in the server it is hosted in, but if I try to send it in any other server, it just shows the emoji name and/or ID. I cannot find any articles or questions that provide any other way of doing this. So in short, how do I get the bot to send an emoji to another server that the emoji isn't being hosted on?
in discord.js v12 it is
const someEmoji = client.emojis.cache.get("<Emoji ID>");
For everyone facing the same issue, you can use client.emojis.get("<Emoji ID>").
Here's a quick example:
const someEmoji = client.emojis.get("<Emoji ID>");
message.channel.send(someEmoji);
Backstory
So, basically what I'm trying to do is using YT, I saw a lockdown command that locks down every channel in the guild once we type "!lockdown" by overwriting the channel permissions for certain roles but if we unlock the channels, everyone is able to type in other channels as permission gets overwritten to SEND message.
Trying to achieve
What I'm trying to achieve is that once we type "!lockdown", it stores the current permissions and then reapply them after I type "!unlock", I'm pretty sure it's possible but I can't figure out how. Any sorts of help will be appreciated!
Thanks in advance!
You may store the permissions of each channel in an object or an array or a database (more efficiency since the bot can be offline between both !lockdown and !unlock).
Then get the datas by a key as the id of each channel to get their permissions and do waht you want.
I'm coding a discord Bot with the discord.js library on a nodeJs server.
Here is my question: is that possible when an event occure (like someone sending a message) that the bot answers to members of a role, or to everyone. The message.reply("my reply") method only answer to the author of the message as I use it for now...
Your problem is that message.reply() is a very limited method: it always mentions the author of the message, and you can't override that.
You need to use a more generic method, channel.send(), and construct the mention yourself. .reply() is just a shortcut for a frequently used form of it, but you need something custom.
Presumably, you want it to happen in the same channel as the message, so you need message.channel.send("Whatever content you want").
Now, to add a role, you need to decide how to pick one. Is it fixed? Then you could hard-code a role mention by role ID: <#&134362454976102401> (of course, it needs to be the role ID you require).
If you want to find a role, for example by name, you need to do that via searching through the guild in question. You can access it though message.guild, but be warned that it will be undefined for DMs.
Then you can do something like
const role = message.guild.roles.find(role => role.name === "NameYouWant");
message.channel.send(`${role} something something`);
because Role objects become mentions when converted to strings.
I want to make my discord bot make an announcement to a certain channel, based on the Channel ID.
I know how to make the bot respond in whatever channel it's talked to, using message.channel.send(), but I was wondering if there was a way to do message.channelID.send() to have the bot talk in a specific channel to make an announcement.
Thanks!
Nathan
client.channels.find("id", "what ever").send(/*...*/)
All channels are stored in a Collection under the Client.channels prpperty which you can use to get it.
Using client.channels.find("id", "what ever").send(/*...*/); will work to send a message to a certain channel, but in the console, an alert is thrown. Using client.channels.get("what ever").send("/*...*/"); does the same job, but without using a discord.js deprecated function.
Thanks to Jonas Wilms!
I have been making a discord bot and wanted to make it send a message to a specific "Welcome" channel. Unfortunately, I have been unable to do so. I tried this.
const welcomeChannel = bot.channels.get("name", "welcome")
welcomeChannel.sendMessage("Welcome\n"+member.user.username);
However in this "welcomeChannel is undefined".
Edit:
I tried using
const welcomeChannel = bot.channels.get("id", "18NUMBERIDHERE")
welcomeChannel.sendMessage("Welcome\n"+member.user.username);
but this is still undefined, strangely
You should use the channnel id instead of it's name.
How to get the channel id of a channel:
Open up your Discord Settings
Go to Advanced
Tick Developer Mode (And close the Discord settings)
Right click on your desired channel
Now there's an option Copy ID to copy the channel id
Also checkout the discord.js documentation for (channel) collections
Furthermore your approach won't work because .get wants a channel id (see the linked documentation above). In case you REALLY want to get an channel by its name, use .find instead for that.
This is however a really bad idea in case your bot runs on more than one server since channel names can now occur multiple times.
You can also use
bot.channels.find("name","welcome").send("Welcome!")
I tried a lot with the same error, and that's how I fixed it. I used client as my Client().
client.channels.cache.get("18NUMBERIDHERE").send("Welcome!");
Your error could come from the fact that you're using bot.channels.get(), which isn't the best idea, because discord.js isn't very friendly when it comes to using .send() on multiple items.
Instead, try to use member.guild.channels.find("name", "channel").send();, if possible. If this is in the client.on("message"), then simply use message.member.channels.find("name", "channel").send();
Sidenote: My memory is mixed up, so if that doesn't work, try .get() instead of find.