当我点击command.processCommand
对象时(当我循环遍历defined[]
中的所有命令时),我想运行放置在thing.process
中的代码,有什么方法可以实现这一点吗?上述循环将在myproject.py中执行
command.py
class Command:
global defined
defined = []
def __init__(self, name):
self.name = name
self.description = "This command lacks a description"
self.args = ""
self.process = None
defined.append(self)
八球
def processCommand():
print('hello')
thing = commands.Command('8ball')
thing.description = "Gives you a response from the mighty 8ball."
thing.process = processCommand
myproject.py
# Cogs
import cogs.commands as commands
import cogs.eightball
import cogs.helloworld
def processCommands(message):
if(message.content[:2] == "b#"):
args = message.content.split(' ')
args[0] = args[0][2:]
for command in defined:
if args[0] == command.name:
command.args = args
command.processCommand
编辑:您需要
process()
而不是processCommand
相关问题 更多 >
编程相关推荐