Little problem with slash commands (discord.js v13) - discord.js

Slash commands work well, no hassle, set with simple code: bot.commands.set(command.name, command)
But I noticed that they are set only when the bot is running and it is added to the Discord server. If the bot is already on the Discord server, and a new command appeared later, then command does not appear in the list. I fix this by a second invitation, but commands in the list start to double, as if they were cloning yourself. Can this be fixable?

You can remove slash commands either from global commands or server commands. Fetching the commands then logging or using another method to show you the command id will allow you to use the delete method.
You can remove slash commands by using bot.application.commands.delete('id here'). (global commands) where bot is the DiscordClient or guild commands: guild.commands.delete('id here'), where guild is the targeted Guild.
These are both functions, and require a command id. You can fetch command ids using: bot.application.commands.fetch().then(c=> console.log(c))(global cmds), guild.commands.fetch().then(c=>console.log(c))(server commands)

Related

Discord.js slash command role/channel options

I'm using Discord.js to write a bot with a number of helpful commands, however I can't seem to find anywhere on either Discord's API docs or Discord.js' docs that lists an example of the json structure for a slash command's role and channel options. I have the commands registering properly, but don't know what sort of data those interactions give me.
TL;DR: what data is returned when I call the following:
interaction.options.getChannel("channelOptionName")
//and
interaction.options.getRole("roleOptionName")
I'm not able to run any code in any reasonable amount of time, so I'm not able to just console.log it and go from there.
Thanks in advance!

Read messages in a discord channel without running client

Is there a way to read the messages on a discord channel using discord.py without running the client? The use case is, I have a lambda function that runs slash commands so that I don't have to have a permanent machine listening. This works fine. I want to make a slash command to read all the messages in the channel and save the attachments in the messages in the channel. All the examples I have seen are to make text bots declaring the commands and end with:
client.run('your-token-here')
Which means it needs to be constantly up. Is this possible?

Discord.net Send A Slash Command With Bot

I'm trying to have my bot simply send a slash command to a specific discord channel. The command would be read by another bot and executed as needed. Is this possible? I'm using discord.net. I have my bot sending plain text messages to the channel with the code below.
await ((ISocketMessageChannel)_client.GetChannel(channelId)).SendMessageAsync("Just Text Here", false, eb.Build());
I'm trying to send the command below. The bot that should respond is noted here. (https://www.alphabotsystem.com/guide/charting).
/c aapl 3m macd mfi
I checked the documentation + newest version methods and I'm afraid there is no such functionality.
In addition developers very often secure their bots by adding a condition which ignores executing commands from Webhooks and Bots.

Slash Commands on Discord

I am the owner of the discord server. My slash commands won't work but they'll work on the app on my phone.
Additionally, if I log out and log in with an alternate account and go to the server, the slash commands work in that instance too, which leads me to believe it's not a missing update.
Any thoughts?

Discord Py Running Command from Server

This might be a duplicated question! sorry I couldn't find an answer!
I have a bot running on a linux server "using discord python lib". I want trigger a command from the server side as a cronjob. Is that possible with the way Discord events are designed? The command needs to run every 5 mins!
I have a db with user/payment data. The command should check if the userid has sent payment. If so then assign them a specific role. Otherwise if the user's payment data is false remove the role.
Right now this works fine with a command I wrote "update_payment" however this command has to be triggered from the discord server manually. I don't want to run this by hand every 5 mins. How do I trigger it from a cronjob on the linux server?
You can use tasks.loop to loop your task:
from discord.ext import tasks
#tasks.loop(minutes=5)
async def update_payment():
pass # whatever here
update_payment.start()

Resources