【发布时间】:2018-07-29 02:20:34
【问题描述】:
我刚开始修改一个响应 Discord 查询的 Python 程序。
运行程序会启动一个 Discord 机器人,它会监听命令并相应地执行任务。现在我想将 bot 对象的引用引用到它开始将一些信息反馈给不和谐频道的方法中,了解现在正在发生的事情。由于某种原因,这不起作用,我不知道为什么。
这是最小的例子。如果缺少什么,请告诉我。完整代码可以查看here。
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 似乎引用了同一个对象。运行此不和谐后说
游戏开始
但他不会说
做了某事
有什么建议可以让我调查一下吗? 提前致谢。
【问题讨论】:
标签: python python-3.6 discord.py