One time only command possible? - discord.js

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.

Related

Nextcord: I want to mention the sender of the slash command I made. How would I go about that?

I'm trying to make this command notify my admins of a bot test and need it to mention the user who called the command. How would I go about that? I don't fully understand how to get that information with slash commands.
#client.slash_command(name= "test", description="(For Deputies or Leader only) Checks the operational state of the client.", guild_ids=[806043206030589952])
#has_any_role(leader_id, deputy_id)
async def test(interaction:Interaction):
bot_log = channel_up(940125176723554394)
await bot_log.send(f'<#&806045254834847776>,{} has started diagnostics for the bot. Please ignore any possible disturbances for the next minute or so.')
Thanks in advance for the advice, it's the first discord bot I've ever created.
EDIT:
In documentation, I found the solution. I have to use interaction.user.mention to get it to mention the user who sent the command. Or at least in theory, I'm dealing with a different issue now. Hopefully this helps people who also were as confused as me out.
You can use the interaction.user.name function with an # at the beginning.
The code should look something like this:
await interaction.response.send_message("#"+str(interaction.user.name))

How to detect when bot is mentioned

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.

Why is my kick command not working? (discord.js)

I've tried using a command handler and the other commands work fine. It's just the kick command that doesn't, can anyone help? https://sourceb.in/8d4f78e43a is the code, thanks!
Since the code is pretty small, you should post it on SO instead of an external link, for archiving for the future and some other reasons you can look up
Also you should mention if you get any error logs, in this case I don't think you would have
The issue is let member = message.guild.members.cache.get(args);
You are passing in an the array args, not a string (which <Collection>.get() requires, you probably meant args[1]:
let member = message.guild.members.cache.get(args[1]);

How to change the default return amount - MailChimp API Json

I am having trouble. Trouble which i am sure is but a moments thought to resolve for our resident experts but, i must learn...
I am returning lists and as I understand it the default return is 25. I have a total of 93.
Below is what i am using (minus our API Key)
http://us1.api.mailchimp.com/1.3/?method=lists&apikey=
I believe that i need a piece of code [limit]=100 as MailChimp suggests but there are numerous pieces of advice on the website and after trying all i am still without my desired output.
If you could advise the way to do this I would be very grateful.
Thanks
Will. :)
Limit should work:
http://us1.api.mailchimp.com/1.3/?method=lists&apikey=YOUR_KEY&limit=100
It was working perfectly fine for me. Check if you are in the right region (in my case I was in us13).

How to find and tail the Oracle alert log

When you take your first look at an Oracle database, one of the first questions is often "where's the alert log?". Grid Control can tell you, but its often not available in the environment.
I posted some bash and Perl scripts to find and tail the alert log on my blog some time back, and I'm surprised to see that post still getting lots of hits.
The technique used is to lookup background_dump_dest from v$parameter. But I only tested this on Oracle Database 10g.
Is there a better approach than this? And does anyone know if this still works in 11g?
Am sure it will work in 11g, that parameter has been around for a long time.
Seems like the correct way to find it to me.
If the background_dump_dest parameter isn't set, the alert.log will be put in $ORACLE_HOME/RDBMS/trace
Once you've got the log open, I would consider using File::Tail or File::Tail::App to display it as it's being written, rather than sleeping and reading. File::Tail::App is particularly clever, because it will detect the file being rotated and switch, and will remember where you were up to between invocations of your program.
I'd also consider locking your cache file before using it. The race condition may not bother you, but having multiple people try to start your program at once could result in nasty fights over who gets to write to the cache file.
However both of these are nit-picks. My brief glance over your code doesn't reveal any glaring mistakes.

Resources