Discord Py Running Command from Server - discord

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

Related

Uniqie Discord.js bot per user on localhost

I've created a discord bot that runs locally on user's machines and I'm not exactly sure how it would work if for example 30 people are running their local instances at the same time. Will other users's instances emit events to eachother or is each running instance only going to care about its own script.

Is it possible to show by command how many voice channels my Discord bot is currently connected to?

I would like to display via command how many voice channels my bot is currently in, is this possible? Maybe also with extra things like the server ID/channel ID. This is not needed though, just the command and the amount would be good.
I already found a method for js but not for Discord.py.
You can use the Bot.voice_clients attribute
voice_states = bot.voice_clients # or client, however you named your instance
await ctx.send(f'I am currently in {len(voice_states)} voice channels')

Discord bot to check if a minecraft server is online

I was wondering if anyone knew of a discord bot that will send a message in a discord sever when a minecraft server is online and send a message when it goes back offline
I've done some googling and can't seem to find one that does what I want there are a couple that u have to manually type commands for and others that appear in the sidebar of discord I simply want one that will do it automatically is there one that exists like this already?
I didn't found any not that already did this, but you can do this pretty easily with the Discord API.
Here is a a script I found that send a message to the server : https://gist.github.com/ianklatzco/769d9e3a991dc2f443a2e105b0157117
You can adapt it to ping the server in a if statement to send if it is online or not
(This script is in python but the Discord api works in more languages)

How to debug a Discord bot while an older version is still running?

I have developed my own simple discord bot (with discord.js) and deployed it to a node server.
Everything is running fine.
Now I want to add some more features to it. During development I'd like to test it locally (of course).
Question is: Can I run my bot locally and test it without disrupting my currently running bot?
If not:
Do I need another bot/token instance?
How can I test my bot without disrupting my currently running bot?
The problem is, when you use the same token for your local bot and for your bot, that is hosted on your node server, it has a total of 2 instances.
Bot on Node server = 1 instance of the bot
Bot on local server = 1 instance of the bot
Which makes a total of 2 instances of the same bot, what you don't want, because then, whenever you execute a command, where the bot is on, it executes the command twice.
Therefore, if I were you, I would create another bot application here and use this new bot to test the bot's new features locally.
99% of all bot developers do it like this, because they don't interrupt the main bot with this method.

Slack and MSSql Query run

Is it possible to run a pre-configured query on MS SQL Server via Slack message?
When I send a message in a specific channel like "run sql" is it possible to slack run a query on my MS SQL Server and return data?
I did this on my iOS app via sql.client 3rd party addon but can't figure it out on slack. Thank you!
(no problem to use 3rd party api or add-ons)
Not with vanilla Slack but if you integrate a "bot" alongside the SqlServerSlackAPI custom integration you can add custom functionality like you are after.
Bot's like Hubot or mmbot will provide the mechanism to write scripts that respond to certain commands or phrases.
I'm currently using mmbot and the SqlServerSlackAPI addon to write custom alerts and commands for monitoring some internal systems with the ability to send commands to Slack to get updates on the status of certain services. Slack fires off a command to a script running in mmbot which triggers a sql procedure to run a query and return results back to Slack which displays this as a message.
If you want something out of the box, check out https://beta.tunnel.ai, it's a slackbot for running SQL queries in slack. It works with any SQL database, including MS SQL. After you add to slack and integrate your database, you'll be able to type SQL in a direct message to the bot, and get data back in Slack. You can save, label, an schedule queries, and export to csv also.
The bot is a hosted solution with two 3rd parties (Tunnel.ai and Slack), and you will need to provide credentials to your database when integrating for the first time (done via conversation with the bot). This might not be for you if you're wary of third party access to your database, but it sounds like you aren't.

Resources