How do I remove code from my discord bot? - discord.js

Can someone please explain how to properly remove code from your discord bot?
So, recently, I started coding a discord bot. So far the only command I've made was, when I say "ping", it replies with "pong."
BUT. It would mention you with the "#" symbol. I didn't like that so I removed the function and instead made it just say "pong" without mentioning you. But, when I tested it, it would mention me and say pong. AND it would also just send a message that said pong. So I removed the whole code. NOPE it still kept replying to my message so I even removed the bot login method but it still kept replying with pong.
If there is something I need to fix in my code, then this is the code (and yes I made a variable for "bot"):
bot.on('message', message =>{
let args = message.content.substring(PREFIX.length).split(" ");
switch(args[0]){
case 'ping':
message.reply('pong!')
break;
}
})

It's because you're using message.reply(). This will always mention the original author. Use message.channel.send() instead.

Okay. So like, I'm actually dumb. All I had to do was restart visual studio

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))

Discord.py adding reaction to webhook.send message

I am able to send messages to my discord channel via webhook very easily, however, when trying to add reactions to the messages it's very difficult, considering my programming is still trivial.
The code line I have right now is:
data_count=1
webhook.send(content=discord.Reaction(message="test", data=data_count, emoji="👍"), file=discord.File("american_eagle_excited.gif"), embed=discord.Embed(title="Sample Embed", description="This is the description"))
Everything, when I break down the parameters I can get to work besides the discord.Reaction class. I feel like I am missing something very easily and after trying to read through the class requirements I had to finally make my way to StackOverflow.
To add a reaction you need the discord.Message instance which is returned by the webhook.send method, you then add the reaction with message.add_reaction
message = webhook.send("test", wait=True, ...) # `wait=True` is really important, if we don't set this the bot will not wait for the message to be returned
await message.add_reaction("👍")

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.

One time only command possible?

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.

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]);

Resources