Limiting certain commands to certain channels [Discord.js] - discord

So I have only found answers to this question for discord.js with commando which won't work with just discord.js
I want to limit an automated reaction to any attachment send in one channel. (And only in that one channel.) So doing it with roles won't work.
Kind regards Per.

If you want that a command can only be done in a certain channel you can check if the id of the channel were the message was sent is the id you have stored to allow the command to be done
if(message.channel.id === 'id of channel'){
//code of command
}

Related

Discord.js Animated Emojis

I have a bot, and I want to use it to send a animated emoji.
I have the emoji ID, <:rgb_lego:993606148580184154>
but whenever I make it send the message, it just says
Pong! 🏓 The round trip took 76ms. ⚡:rgb_lego:
what am I doing wrong?
It depends on what server (guild) you sent it and how exactly you do it.
Guess you need to check & fetch the requested custom emojie from server and then sent it.
You might wanna check Discord.js docs for that. But if I remember it correctly, emojies should be accessed by bot via:
client.guild.emojis.[methodName] via GuildEmojiManager
The second problem could be relevant to the server, where you want to sent it, doesn't have the required emojie, so in that case it has been delivered as a text ref, not an emojie itself or the bot account doesn't have premium features required for using emojies or so on.

How to mention a user mentioned in the command discord js

So im working on a discord bot, and working on a command where it mentions a user. For example: -fakekick #user and the bot would say User has been kicked I've read through the docs and found a few sites but I couldn't really understand it as I just started discord js a few days ago. Thanks
To get the user object of a mentioned user, you can very simply use the mentions extension of the message object. We can very simply use it in order to define our user, and later on, mention him in a future message. That can be done very simply as so:
const user = message.mentions.users.first(); // Would get the first mentioned user's object
message.channel.send(`${user} has been kicked!`); // To mention a user, you simply need to mention his user object.

YAGPDB Discord Bot - Custom command to limit reaction

I am trying to create a voting channel where the YAGPDB bot will automatically react "👍" and "👎" to every message posted in that particular channel. And people will be able to react only one of them. Can someone advise on how to do it?
I was able to write the code this far:
{{addMessageReactions nil $.Message.ID ":thumbsup:" ":thumbsdown:"}}
On the Role Command category under Role Commands, just set it to Mode: Single

Why does client.users.cache only show 2 users discord.js

For a server of mine, I need my bot to DM everyone at regular periods of time. I use
client.users.cache.get(args[1]).send(toSend);
to do this, where args[1] contains the user's id and toSend is the message to send. However, it just turns up Cannot read property 'send' of undefined. Then I tried logging client.users.cache to the console and it appears that only 2 users are in it, the bot itself and me. Why is this so, given that the server has at least 30 users?

Deleting every channel in a specified category in discord.py

I am trying to delete every channel in a specified category in discord.py.
My code so far:
category = client.get_channel(my_id_here)
I was thinking of iterating through each of the channels in that category however I'm not sure how to go about doing so.
I saw a similar post on this however that's in discord.js so I would need the discord.py equivalent.
Figured out the solution, hope it helps someone:
category = client.get_channel(id_here)
for channel in category.voice_channels:
await channel.delete()
If you want to remove text channels, replace voice_channels with text_channels

Resources