【问题标题】:Running two discord bot tokens at the same time同时运行两个不和谐机器人令牌
【发布时间】:2021-03-25 19:30:11
【问题描述】:

我需要帮助来制作一个脚本,让您可以运行超过 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' 对象没有属性 'strip',谁能帮帮我?

【问题讨论】:

  • 要么avoid using the decorators,要么将其抽象为一个新模块并创建该模块的多个实例(在函数中或作为类)

标签: python discord discord.py token


【解决方案1】:

不妨试试

for tok in token:
  client.run(tok)

client = commands.Bot(command_prefix='?')
bot = commands.Bot(command_prefix='?')

bot.run('bottoken')
client.run('bottoken')

【讨论】:

  • 我试着让它像这样:import discord from discord.ext import commands import asyncio client = commands.Bot(command_prefix='?') token = ["ODExMzI4NTU0NTc4MDgzODcx.YCwmmQ.xxxxxxxxxx", "ODExMzI2MTU1NzM0OTA4OTQ4.YCwkXQ.xxxxxxxx"] for tok in token: client.run(tok) 但它只运行 1 个机器人
  • 哦,那么我知道如何
猜你喜欢
  • 2021-06-11
  • 1970-01-01
  • 1970-01-01
  • 2020-03-26
  • 1970-01-01
  • 2018-07-21
  • 2018-11-10
  • 2018-04-17
  • 2019-05-11
相关资源
最近更新 更多