[英]Running two discord bot tokens at the same time
I need help to make a script that lets you run more than 1 bot token, without repeating the code of the commands all times for every bots, example:我需要帮助来制作一个脚本,让您运行超过 1 个机器人令牌,而无需为每个机器人始终重复命令代码,例如:
import discord
from discord.ext import commands
import asyncio
client1 = commands.Bot(command_prefix='?')
client2 = commands.Bot(command_prefix='?')
@client1.event
async def on_ready():
await client1.change_presence(activity=discord.Game('?commands'))
print('Connected to bot: {}'.format(client1.user.name))
print('Bot ID: {}'.format(client1.user.id))
@client2.event
async def on_ready():
await client2.change_presence(activity=discord.Game('?commands'))
print('Connected to bot: {}'.format(client2.user.name))
print('Bot ID: {}'.format(client2.user.id))
loop = asyncio.get_event_loop()
loop.create_task(client1.start('ODExMzI2MTU1NzM0OTA4OTQ4.YCwkXQ.xxxxxxxxxxxxxxxxxxxxxxxxxxx'))
loop.create_task(client2.start('ODExMzI4NTU0NTc4MDgzODcx.YCwmmQ.xxxxxxxxxxxxxxxxxxxxxxxxxxx'))
loop.run_forever()
I wanted to turn it into something like this:我想把它变成这样的东西:
import discord
from discord.ext import commands
import asyncio
client = commands.Bot(command_prefix='?')
token = ["ODExMzI2MTU1NzM0OTA4OTQ4.YCwkXQ.xxxxxxxxxxxxxxxxxxxxxxxxxxx", "ODExMzI4NTU0NTc4MDgzODcx.YCwmmQ.xxxxxxxxxxxxxxxxxxxxxxxxxxx"]
@client.event
async def on_ready():
await client.change_presence(activity=discord.Game('?commands'))
print('Connected to bot: {}'.format(client.user.name))
print('Bot ID: {}'.format(client.user.id))
client.run(token)
But it says Exception has occurred: AttributeError 'list' object has no attribute 'strip', anyone can help me?但它说发生了异常:AttributeError 'list' object has no attribute 'strip',谁能帮帮我?
Maybe try也许试试
for tok in token:
client.run(tok)
or或者
client = commands.Bot(command_prefix='?')
bot = commands.Bot(command_prefix='?')
bot.run('bottoken')
client.run('bottoken')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.