Here is an idea of the code that would work in my ideal world:
client.guild.cache.get(`${server_ID}`).roles.cache.get(`${role_ID}`).setPermissions(123456789);
But, as expected, it doesn't work.
(Cannot read property 'cache' of undefined)
I researched here, on a lot of forum and website but I couldn't figured out... Do you have any idea ?
If you think I could improve the question, tell me
I forgot the s at the end of guild (I now hate myself)
client.guilds.cache.get(`${server_ID}`).roles.cache.get(`${role_ID}`).setPermissions.setPermissions(0123456789)
Related
Before you mark this a duplicate, I have already tried this post: How to detect if the bot has been mentioned?
else if (message.mentions.has(client.user)) {
message.channel.send("https://images-ext-2.discordapp.net/external/L-agoqC2Qsf2sdz4tdrcD5hUiJe6moglhwHjXPi8McE/https/i.imgflip.com/3ia3r2.png")
console.log('Bot was mentioned')
}
I have it to log when it is mentioned but doesn't log, so i figure that it doesn't detect it being mentioned. Is there a different way to detect if the bot is mentioned?
The annoying thing with if (message.mentions.has(...) is that it would make the bot react even when #everyone or #here are mentioned, hence why I don't recommend using it.
The best thing yet, unfortunately, the ugliest thing to do, would be to have an if statement checking if the message includes a client mention, that can be done using:
if (message.content.includes(`<#!${client.user.id}>`) console.log('Bot was mentioned!')
In order to check for a mention to a specific Guild#GuildMember, you should write
if (message.mentions.members.has(<Client>.user.id)) {
message.channel.send("https://images-ext-2.discordapp.net/external/L-agoqC2Qsf2sdz4tdrcD5hUiJe6moglhwHjXPi8McE/https/i.imgflip.com/3ia3r2.png");
console.log('Bot was mentioned');
}
This will check for the direct mention to the bot.
I was wondering if its possible to have a command that can be used only once by a user on discord, if so please can someone give me the code for it I would much appreciate it.
First of all, SO is not a code-as-a-service platform or whatever. You give code, you tell your problem, and we help you. It's how it works. Here's my answer.
Of course, yes, it is possible. Anything that is based on logic can be reproduced by a computer. You just need to learn how to think as a computer would. In your case, it'd look like that in pseudo-code.
when the command is received:
has the user already used this command?
yes:
return "You've already used this command!"
no:
do the work
You would need to save the users who already have used the command. For simplicity reasons, the database you would like to use will be represented as an array.
let blockList = []
client.on('message', msg => {
if (msg.content === "!command") {
if (blockList.includes(msg.author.id)) return msg.reply("You've already used this command!");
msg.reply("This is the first time you're using this command! You won't be able to do it again. BUT since the blocklist is stored as an array, the list will be cleared when the program will stop.")
return blockList.push(msg.author.id)
}
})
Here you have the logic. It's up to you to integrate it into your code, with your database.
I hope I helped, and please, do not post another question that looks like that. Try, search, and ask! It'll be much nicer to help you, and I'm sure you would learn much more.
I'm trying to write a discord bot and am constantly getting this error whenever i try to run it.
TypeError: discord.collection is not a constructor
It's from this line of code
bot.commands = new discord.collection();
I'm not the best at JavaScript and have looked around google and can't find anything that matches my exact issue, all the ones I find have the same error but are something completely different.
whether or not this command is outdated or no longer in use I am unsure of but any help would be greatly appreciated!
It's Collection, not collection. The standard for naming classes is always first letter capitalized.
i have been trying a code found here to add rating bar but i got an error on
cb.setToggleButton(
where the "setToggleButton" method didn't or doesn't exist anymore
any idea if it has been update cause the post i tagged was back from 2014
That method doesn't exist, it should be setToggle(true). Notice in the linked post it just said setToggleButton( without even a closing bracket. Since this was written a while back I'm guessing I just switched a desktop to check the method name and got distracted then forgot to fix that. Hazards of blind coding without the comfort of an IDE.
#devcrp actually wrote the correct answer before but unfortunately he deleted it. If he undeletes it his answer should be accepted.
I ran into another snag while going through the ThinksterIO Learn to Build Real Time Webapps tutorial around the 90% mark where one is shown how to add and delete comments:
https://thinkster.io/angulartutorial/learn-to-build-realtime-webapps/#adding-comments-functionality-to-the-post-service-9
Every time I click the Post Comment button absolutely nothing happen and I simply can't figure it out. I am expecting some kind of error to show up but nil. It's as if the button is not hooked up to the function. I was so frustrated that I eventually just copy and pasted the code from the tutorial to make sure I had it down right. Even after doing that it still didn't work.
I've created a Plunker with this app running over here http://embed.plnkr.co/OhzDTU/preview
You can sign in with the email user#user.com and 1234 password. You will then be able to try to comment on posts. Any ideas on what is going wrong here?
UPDATE
I took away the user user#user.com and 1234 password since problem is now fixed.
Your add comment button is in showpost.html, which is rendered by PostViewCtrl. However, your addComment method is attached to the scope of PostsCtrl (it doesn't exist when you try to click it). The simplest answer here is just to move addComment() over to the other controller.
Regarding the lack of error messages, I don't think that you can get an error for this. I had a look at the docs for $log and tried to decide if you could add some debugging output, but it looks like it's already on (i.e. the lack of a method seems to fail silently).
About your only option here is to try something like {{addComment|json}} in the view to see if it exists, but you'd first have to suspect that it didn't.