我刚开始修改Python程序,它可以在不和谐的情况下响应查询。
运行该程序将启动一个听命令并相应执行任务的不和谐机器人。现在,我想在方法中引用bot对象,它开始将一些信息反馈给不和谐的通道,了解目前正在发生的事情。因为某些原因,这不起作用,我也搞不懂原因。
这是最小的例子。如果遗漏了什么请告诉我。完整的代码可以检查这里。
discord.py
from communitybot.playgame import Game
from discord.ext.commands import Bot
from communitybot.utils import (
start_game
)
bot = Bot(
description=description,
command_prefix="$",
pm_help=False)
bot.remove_command('help')
@bot.group(pass_context=True)
async def game(ctx):
if ctx.invoked_subcommand is None:
await bot.say('Usage: $game start')
@game.command()
async def start():
start_game(bot)
await bot.say("**Game started**")
utils.py
from communitybot.playgame import Game
from communitybot.settings import BOT_ACCOUNT
from steem import Steem
def start_game(discordbot=None):
c = Game(
get_steem_conn(),
BOT_ACCOUNT,
discordbot = discordbot
)
c.start_game()
playgame.py
class Game:
def __init__(self, steemd_instance, bot_account, discordbot=None):
self.s = steemd_instance
self.bot_account = bot_account
self.discord = discordbot
def start_game(self):
#do something
if self.discord is not None:
self.discord.say('**did something**')
来自discord.py的机器人和来自playgame.py的self.discordbot似乎被引用到同一个对象。跑完这场争吵后,他说
游戏启动
但他不肯说
做了一些的事
有什么不对的建议吗?我可以调查一下吗?提前谢谢。
https://stackoverflow.com/questions/48856162
复制