2017-04-14 10 views
0

나는 간단한 사운드 클립을 완성하는 중이다. Discord bot 파이썬으로 기본적인 음악 봇 예제를 재활용하여 만들었다. 봇이 원하는 모든 것은 명령 (! womble)을 호출 한 사용자의 음성 채널에 들어가고, 사운드 클립 폴더에서 임의의 사운드 클립을 재생 한 다음 음성 채널을 나가는 것입니다.내 불화 봇이 내 명령을 한 번만 실행하는 이유는 무엇입니까?

"간단합니다." 물론이 API를 사용하는 것은 아닙니다.

시행 착오를 거친 후 최소 3 개의 API 개정판을 살펴본 결과, 실제로 한 번 명령을 수행 할 수있는 로봇이 생겼습니다. 명령에 대한 더 이상의 프롬프트는 귀뚜라미로 만난다. 나는 소환을 할 수 있으며 봇을 채널로 가져 왔지만! womble 명령은 더 이상 작동하지 않습니다. 내가 파이썬 채팅으로가는 시도

def bot_leave(self, ctx): 
    state = self.get_voice_state(ctx.message.server) 
    coro = state.voice.disconnect() 
    fut = asyncio.run_coroutine_threadsafe(coro, state.voice.loop) 
    try: 
     fut.result() 
    except: 
     # an error happened sending the message 
     pass 

@commands.command(pass_context=True, no_pm=True) 
async def womble(self, ctx): 
    state = self.get_voice_state(ctx.message.server) 
    opts = { 
     'default_search': 'auto', 
     'quiet': True, 
    } 

    if state.voice is None: 
     success = await ctx.invoke(self.summon) 
     if not success: 
      return 

    try: 
     random_clip = clip_dir + "\\" + random.choice(os.listdir(clip_dir)) 
     player = state.voice.create_ffmpeg_player(random_clip, after=lambda: self.bot_leave(ctx)) 
     player.start() 
    except Exception as e: 
     fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' 
     await self.bot.send_message(ctx.message.channel, fmt.format(type(e).__name__, e)) 

는 불화의 API 서버입니다,하지만 내 로봇처럼 많이, 나는 귀뚜라미 만난거야. (이미 대화가 4 개있는 채팅에서 지원을 요청하려고하는 것 같아요.)

답변

0

더 이상 도움이 필요하지 않을 수도 있지만 coroutine.result() 및 직접 실행하십시오. 즉 변화 :

def bot_leave(self, ctx): 
state = self.get_voice_state(ctx.message.server) 
coro = state.voice.disconnect() 
fut = asyncio.run_coroutine_threadsafe(coro, state.voice.loop) 
try: 
    fut.result() 
except: 
    # an error happened sending the message 
    pass 

에 : 나는 당신의 코드를보고 생각할 수있는 유일한 것은, 그러나 문제는 다른 코드에서 거짓말을 할 수

def bot_leave(self, ctx): 
state = self.get_voice_state(ctx.message.server) 
coro = state.voice.disconnect() 
try: 
    asyncio.run_coroutine_threadsafe(coro, state.voice.loop) 
except: 
    # an error happened sending the message 
    pass 

.

+0

웰프 (Welp) : 한 가지 측면에서 봇을 개선하는 데 성공했습니다. 이제 봇이 서버에 다시 참여하게됩니다. 첫 번째 시간은 완벽하게 작동합니다. 두 번째로 봇이 나타나서 바로 거기에 있습니다. 한 번 이상 플레이어를 만드는 것이 좋지 않다고 생각하거나 적어도 내가 추측하고있는 것입니다. –