random.random - random() 不接受任何参数(给定 1 个)
random.random - random() takes no arguments (1 given)
我试图让 random.random 从 cmd_advice 中的函数列表中进行选择(我假设这就是它的工作原理?)但是我的调试器向我显示 TypeError: random() takes no参数(给定 1 个)。
我是新手,所以如果这看起来很愚蠢,我深表歉意。
# minqlbot - A Quake Live server administrator bot.
# Copyright (C) Mino <mino@minomino.org>
# This file is part of minqlbot.
# minqlbot is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# minqlbot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with minqlbot. If not, see <http://www.gnu.org/licenses/>.
import minqlbot
import random
class fun(minqlbot.Plugin):
def __init__(self):
self.add_command("cookies", self.cmd_cookies)
self.add_command("<3", self.cmd_heart, channels=("chat", "team_chat", "tell"))
self.add_command("wife", self.cmd_wife)
self.add_command("advice", self.cmd_advice)
def cmd_cookies(self, player, msg, channel):
channel.reply("^7For me? Thank you, {}!".format(player))
def cmd_heart(self, player, msg, channel):
s = ("^1\r oo oo"
"\no o o o"
"\no o o"
"\n o o"
"\n o o"
"\n o o"
"\n o")
channel.reply(s.replace("o", "\x08"))
def cmd_wife(self, player, msg, channel):
channel.reply("^4I love my wife more than anything in the whole wide world!")
def cmd_advice(self, player, msg, channel):
def advice1():
channel.reply("This is advice1")
def advice2():
channel.reply("This is advice2")
def advice3():
channel.reply("This is advice3")
choice = [advice2(), advice3(), advice1()]
random.random(choice)
使用 random.choice
(docs) 而不是 random.random
。
我试图让 random.random 从 cmd_advice 中的函数列表中进行选择(我假设这就是它的工作原理?)但是我的调试器向我显示 TypeError: random() takes no参数(给定 1 个)。
我是新手,所以如果这看起来很愚蠢,我深表歉意。
# minqlbot - A Quake Live server administrator bot.
# Copyright (C) Mino <mino@minomino.org>
# This file is part of minqlbot.
# minqlbot is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# minqlbot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with minqlbot. If not, see <http://www.gnu.org/licenses/>.
import minqlbot
import random
class fun(minqlbot.Plugin):
def __init__(self):
self.add_command("cookies", self.cmd_cookies)
self.add_command("<3", self.cmd_heart, channels=("chat", "team_chat", "tell"))
self.add_command("wife", self.cmd_wife)
self.add_command("advice", self.cmd_advice)
def cmd_cookies(self, player, msg, channel):
channel.reply("^7For me? Thank you, {}!".format(player))
def cmd_heart(self, player, msg, channel):
s = ("^1\r oo oo"
"\no o o o"
"\no o o"
"\n o o"
"\n o o"
"\n o o"
"\n o")
channel.reply(s.replace("o", "\x08"))
def cmd_wife(self, player, msg, channel):
channel.reply("^4I love my wife more than anything in the whole wide world!")
def cmd_advice(self, player, msg, channel):
def advice1():
channel.reply("This is advice1")
def advice2():
channel.reply("This is advice2")
def advice3():
channel.reply("This is advice3")
choice = [advice2(), advice3(), advice1()]
random.random(choice)
使用 random.choice
(docs) 而不是 random.random
。