这是我的小问题:
if start == False:
start = True
players_list.append(ctx.message.author.id)
await self.client.send_message(channel, '**Session created by {}** Wait another player to join..'.format(ctx.message.author))
开始boolean,如果if导致错误bcs,我将start = True
放入if内
完整代码:
import discord
from discord.ext import commands
players_list = []
wolves_list = []
villagers_list = []
start = False
class Werewolf:
def __init__(self, client):
self.client = client
@commands.command(pass_context = True)
async def playww(self, ctx):
channel = ctx.message.channel
if start == False:
start = True
players_list.append(ctx.message.author.id)
await self.client.send_message(channel, '**Session created by {}** Wait another player to join..'.format(ctx.message.author))
else:
await self.client.send_message(channel, '**Session already created!**')
@commands.command(pass_context = True)
async def joinww(self, ctx):
channel = ctx.message.channel
id_player = ctx.message.author.id
if start == True:
if id_player not in players_list:
players_list.append(id_player)
await self.client.send_message(channel, '**{}** joined the game!'.format(ctx.message.author))
else:
await self.client.send_message(channel, '**{}** already inside player list!'.format(ctx.message.author))
else:
await self.client.send_message(channel, 'Create session first by `-playww` command!')
def setup(client):
client.add_cog(Werewolf(client))
有什么想法吗?
答案 0 :(得分:0)
使start
(以及所有其他“全局”变量)成为Werewolf
嵌齿轮的属性。
class Werewolf:
def __init__(self, client):
self.client = client
self.players_list = []
self.wolves_list = []
self.villagers_list = []
self.start = False