Python random.random-random()不接受任何参数(给定1个)

Python random.random-random()不接受任何参数(给定1个),python,random,Python,Random,我试图让random.random从cmd_advice中的函数列表中进行选择(我假设它就是这样工作的?),但是我的调试器向我显示TypeError:random()不接受任何参数(给定1) 我是新来的,所以如果这看起来很愚蠢,我道歉 # minqlbot - A Quake Live server administrator bot. # Copyright (C) Mino <mino@minomino.org> # This file is part of minql

我试图让random.random从cmd_advice中的函数列表中进行选择(我假设它就是这样工作的?),但是我的调试器向我显示TypeError:random()不接受任何参数(给定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)
#minqlbot-一个Quake Live服务器管理员bot。
#版权所有(C)Mino
#此文件是minqlbot的一部分。
#minqlbot是免费软件:您可以重新发布和/或修改它
#它是根据GNU通用公共许可证的条款发布的
自由软件基金会,或者许可证的第3版,或者
#(由您选择)任何更高版本。
#minqlbot的发布是希望它会有用,
#但无任何保证;甚至没有任何关于
#适销性或适合某一特定目的。见
#有关更多详细信息,请参阅GNU通用公共许可证。
#您应该已经收到GNU通用公共许可证的副本
#还有minqlbot。如果没有,请参阅。
导入minqlbot
随机输入
类乐趣(minqlbot.Plugin):
定义初始化(自):
self.add_命令(“cookies”,self.cmd_cookies)

self.add_命令(使用
random.choice
()而不是
random.random

考虑在发布时编写更简洁的示例代码(例如,
random.random([1,2,3])
说明了问题。减少我们排序的积垢!@larix-该链接似乎与此答案无关。
def cmd u建议(self,player,msg,channel):
def advice1():
channel.reply(“这是advice1”)
def advice2():
def advice2():
channel.reply(“这是advice3”)
myList=[advice2(),advice3(),advice1()]
random.choice(myList)
返回以下内容:@larix代码的问题是您的
choice
列表是函数调用列表,而不是函数。这将导致所有3个通知都被发送。相反,将其设置为通知函数列表
choice=[advice2,advice3,advice1]
并调用一个随机的
random.choice(choice)(
@larix注意,
[advice2(),advice3(),advice1()]
调用三个函数,它们打印一些内容,但不返回任何内容。您将打印所有3个内容,并且列表本身是
[None,None,None]
@MaciejGol谢谢,终于成功了!我昨晚试过了,但用了另一种方式使用了随机函数,并在调试器中给了我一个seq msg