P
P
prostiti2021-10-20 18:28:12
Python
prostiti, 2021-10-20 18:28:12

Several tokens and bots, but 1 code, how to do this?

Approximately, what I was looking for was here, but this is not it. https://qna.habr.com/q/924649

Purpose: To launch several bots using one script/code, not simultaneously, but in turn, while having several tokens.

I have a script / code and there are 2 tokens for an example, 2 tokens are enough for me, but if everything works as it should, then there will be several times more tokens. With the help of one script, I want to launch several bots, not simultaneously, but in turn, otherwise, I want to launch another bot using one bot, but at the same time, the bot through which I launched the script would be turned off and another bot would start working.

I hope my thought was clear and will not turn out to be nonsense / before / it is not clear what ...

In this example, I tried to do the same as they do the mechanics of changing the prefix in bots, but this does not work with the token.

Here is an example of the code I tried to implement:

import typing
import asyncio
import discord
from datetime import datetime
from discord.ext import commands
from discord.ext.commands import has_permissions
from dhooks import Webhook, Embed

import discord
import json
from discord.ext import commands
async def get_token(bot, message):
  with open('tokens.json', 'r') as file:
    tokens = json.load(file)
    out_data = [ i["token"] for i in tokens ]
    print(out_data[2])
    token_bot = out_data[2]
  with open('out.json', mode='w', encoding='utf-8') as outfl:
    json.dump(out_data, outfl, sort_keys=True, indent=4)
    
bot = commands.Bot(command_prefix = get_prefix, intents = discord.Intents.all())
bot.remove_command( 'help' )

@bot.event
async def on_ready():
  print('Bot is ready.')
bot.run(get_token, bot = True)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Nevzorov, 2021-10-20
@fixator10

asyncio.gather
Client.start

P
prostiti, 2021-10-21
@prostiti

Is this the answer?
It is possible in more detail?

P
Pavlosik, 2021-10-21
@Pavlosik

Want to create a script that launches bots one by one?
Create a bot file and write the following
@echo off
call %~dp0proj\venv\Scripts\activate (if there is venv) if not then don't care just delete this line
cd %~dp0 folder
python file name
python name 2
python bots and so on
pause
all bots must be in the same folder

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question