python - 同时运行两个不和谐机器人令牌
问题描述
我需要帮助来制作一个脚本,让您运行超过 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()
我想把它变成这样的东西:
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)
但它说发生了异常:AttributeError 'list' object has no attribute 'strip',任何人都可以帮助我吗?
解决方案
也许试试
for tok in token:
client.run(tok)
或者
client = commands.Bot(command_prefix='?')
bot = commands.Bot(command_prefix='?')
bot.run('bottoken')
client.run('bottoken')
推荐阅读
- vba - 如何暂时停止传入电子邮件的事件脚本?
- c++ - C ++从子线程中杀死所有父子线程
- scala - 类路径中缺少“type scala.collection.generic.GenericTraversableTemplate”
- html - 如何根据包含 Google 表格数据的模板获取 HTML 代码
- intellij-idea - Intellij - 更改 TestNG 运行配置的默认类路径
- reactjs - 在 reactJS 中声明状态
- c# - 为什么在尝试保存变量值数据并加载它们时出现异常?
- c# - 无法在文件后面的代码中访问标签控件(放置在 ItemTemplate 中)
- html - justify-content 不适用于自动边距
- c - 为什么我不能使用“scanf_s”同时读取一个字符和一个数字?