GVKun编程网logo

Python-为什么on_message会停止命令的工作?(导致python停止工作的原因)

21

对于Python-为什么on_message会停止命令的工作?感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解导致python停止工作的原因,并且为您提供关于appium+python运行报

对于Python-为什么on_message会停止命令的工作?感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解导致python停止工作的原因,并且为您提供关于appium+python 运行报错:status":33,"value":{"message":"A new session coul...、BEGIN_MESSAGE_MAP 和END_MESSAGE_MAP() 这两个宏的具体实现与作用 (转)、Discord.py python message.content、discord.py 中 on_message 的冷却时间的宝贵知识。

本文目录一览:

Python-为什么on_message会停止命令的工作?(导致python停止工作的原因)

Python-为什么on_message会停止命令的工作?(导致python停止工作的原因)

基本上,一切似乎都可以正常运行并启动,但是由于某些原因,我无法调用任何命令。我已经很轻松地环顾了一个小时,然后看了一些示例/观看视频,但我终生无法找出问题所在。代码如下:

import discordimport asynciofrom discord.ext import commandsbot = commands.Bot(command_prefix = ''-'')@bot.eventasync def on_ready():    print(''Logged in as'')    print(bot.user.name)    print(bot.user.id)    print(''------'')@bot.eventasync def on_message(message):    if message.content.startswith(''-debug''):        await message.channel.send(''d'')@bot.command(pass_context=True)async def ping(ctx):    await ctx.channel.send(''Pong!'')@bot.command(pass_context=True)async def add(ctx, *, arg):    await ctx.send(arg)

我在on_message中拥有的调试输出实际上可以正常工作并做出响应,并且整个bot都可以运行,没有任何异常,但是它只是不会调用命令。

答案1

小编典典

覆盖提供的默认值将on_message禁止运行任何其他命令。要解决此问题,请bot.process_commands(message)在的末尾添加一行on_message。例如:

@bot.eventasync def on_message(message):    # do some extra stuff here    await bot.process_commands(message)

默认值on_message包含对此协程的调用,但是当你用自己的协程覆盖它时on_message,你需要自己调用它。

答案2

小编典典

采用:

>>> import datetime>>> datetime.datetime.now()datetime.datetime(2009, 1, 6, 15, 8, 24, 78915)>>> print(datetime.datetime.now())2009-01-06 15:08:24.789150

而只是时间:

>>> datetime.datetime.now().time()datetime.time(15, 8, 24, 78915)>>> print(datetime.datetime.now().time())15:08:24.789150

有关更多信息,请参见文档。

要保存输入,可以datetimedatetime模块中导入对象:

>>> from datetime import datetime

然后datetime.从以上所有位置移除引线。

appium+python 运行报错:status

appium+python 运行报错:status":33,"value":{"message":"A new session coul...

报错日志:

info: [debug] Retrying restartAdb

info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20131030\sdk\platform-tools\adb.exe -s fb2953b8 kill-server

info: [debug] Getting connected devices...

info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20131030\sdk\platform-tools\adb.exe -s fb2953b8 devices

info: [debug] 20 device(s) connected

info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)

info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20131030\sdk\platform-tools\adb.exe -s fb2953b8 wait-for-device

info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20131030\sdk\platform-tools\adb.exe -s fb2953b8 kill-server

info: [debug] Getting connected devices...

info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20131030\sdk\platform-tools\adb.exe -s fb2953b8 devices

info: [debug] 20 device(s) connected

info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)

info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20131030\sdk\platform-tools\adb.exe -s fb2953b8 wait-for-device

info: [debug] executing cmd: D:\adt-bundle-windows-x86_64-20131030\sdk\platform-tools\adb.exe -s fb2953b8 shell "echo ''ready''"

info: [debug] Sent shutdown command, waiting for UiAutomator to stop...

warn: UiAutomator did not shut down fast enough, calling it gone

info: [debug] Cleaning up android objects

info: [debug] Cleaning up appium session

error: Failed to start an Appium session, err was: Device did not become ready in 5 secs; are you sure it''s powered on?

info: [debug] undefined

info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created.","origValue":"Device did not become ready in 5 secs; are you sure it''s powered on?"},"sessionId":null}

info: <-- POST /wd/hub/session 500 86259.711 ms - 171

 

解决:添加代码,设置androidDeviceReadyTimeout’默认时间 5s 20s.

android[''androidDeviceReadyTimeout''] = ''20''

如图:

 

 

 

BEGIN_MESSAGE_MAP 和END_MESSAGE_MAP() 这两个宏的具体实现与作用 (转)

BEGIN_MESSAGE_MAP 和END_MESSAGE_MAP() 这两个宏的具体实现与作用 (转)

mfc command class 框架 null

BEGIN_MESSAGE_MAP和END_MESSAGE_MAP
首先看定义
#define BEGIN_MESSAGE_MAP(theClass, baseClass) /
      const AFX_MSGMAP* theClass::GetMessageMap() const /
            { return &theClass::messageMap; } /
      AFX_COMDAT AFX_DATADEF const AFX_MSGMAP theClass::messageMap = /
      { &baseClass::messageMap, &theClass::_messageEntries[0] }; /
      AFX_COMDAT const AFX_MSGMAP_ENTRY theClass::_messageEntries[] = /
      { /
实际应用BEGIN_MESSAGE_MAP(myview,CView)等价于
      const AFX_MSGMAP* myview::GetMessageMap() const /
            { return & myview::messageMap; } /
      AFX_COMDAT AFX_DATADEF const AFX_MSGMAP myview::messageMap = /
      { & CView::messageMap, & myview::_messageEntries[0] }; /
      AFX_COMDAT const AFX_MSGMAP_ENTRY myview::_messageEntries[] = /
      { /
END_MESSAGE_MAP和BEGIN_MESSAGE_MAP是成对出现的
#define END_MESSAGE_MAP() /
            {0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 } /
      }; /
class myview:public CView
{
public:
      static const CRuntimeClass classmyview;
      virtual CRuntimeClass* GetRuntimeClass() const;
      static CObject* __stdcall CreateObject();
public:
      void OnDraw(CDC *d)
      {
            mydoc *b;
            b=(mydoc *)m_pDocument;
            d->SetTextColor(RGB(0,0,0)) ;
            d->TextOut(b->point.x,b->point.y ,b->s) ;
           
      }
     
      void OnLButtonDown(UINT nFlags,CPoint p)
      {
            mydoc *b;
            b=(mydoc*)m_pDocument;
            b->point.x=p.x;
            b->point.y=p.y;
            Invalidate();
      }
private:
              static const AFX_MSGMAP_ENTRY _messageEntries[];
protected:
              static AFX_DATA const AFX_MSGMAP messageMap;
              virtual const AFX_MSGMAP* GetMessageMap() const;          
};
 
CObject* __stdcall myview::CreateObject()
{ return new myview; }
 
const CRuntimeClass myview::classmyview =
{
      "myview", sizeof(class myview), 0xFFFF, myview::CreateObject,
            (CRuntimeClass*)(& CView::classCView), NULL
};
CRuntimeClass* myview::GetRuntimeClass() const
{
      return ((CRuntimeClass*)(& myview::classmyview));
}
 
const AFX_MSGMAP* myview::GetMessageMap() const
{ return & myview::messageMap; }
 
 const AFX_MSGMAP myview::messageMap =
{ & CView::messageMap, & myview::_messageEntries[0] };
 
 const AFX_MSGMAP_ENTRY myview::_messageEntries[] =
{
 
     {
     WM_LBUTTONDOWN, 0, 0, 0, AfxSig_vwp,
     (AFX_PMSG)(AFX_PMSGW)(void (CWnd::*)(UINT, CPoint))&OnLButtonDown
     },
          
 {0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 }
 
};
 
DECLARE_MESSAGE_MAP、BEGIN_MESSAGE_MAP、END_MESSAGE_MAP以及ON_COMMAND、ON_MESSAGE等宏最终作用的结果是在你的类中生成了一个名为lpEntries的数组,该数组中将填入每个你关心的消息和此消息对应的处理函数。应用程序框架生成的WindowProc接收到一个消息后,会按照一定的原则轮询个各类(CView、CDocument、CFrameWnd、CWinApp)的messageEntries数组,检查该数组中有没有对应的消息,如果有,就调用相应的响应函数;如果没有,就换下一个类继续检查。当所有的有关的类都被检查完后仍未发现响应函数时,便将此消息丢给DefWindowProc处理。  
      MFC之所以这样做,主要是考虑到使用虚函数会造成过大的系统开销。以上只是实现的简单原理,详细过程你还是去看MFC的源代码吧。我个人认为,MFC在消息处理这事上,做得还是相当漂亮。 有关进一步的资料请自己查询有关MFC的书籍

Discord.py python message.content

Discord.py python message.content

使用

if not message.guild:
    <do stuff>

忽略公会中的消息

discord.py 中 on_message 的冷却时间

discord.py 中 on_message 的冷却时间

您应该使用 CooldownMapping.from_cooldownon_message 事件添加冷却时间,例如:

import typing
import discord
from discord.ext import commands

class SomeCog(commands.Cog):
    def __init__(self,bot):
        self.bot = bot
        self._cd = commands.CooldownMapping.from_cooldown(1,6.0,commands.BucketType.member) # Change accordingly
                                                        # rate,per,BucketType

    def get_ratelimit(self,message: discord.Message) -> typing.Optional[int]:
        """Returns the ratelimit left"""
        bucket = self._cd.get_bucket(message)
        return bucket.update_rate_limit()


    @commands.Cog.listener()
    async def on_message(self,message):
        if "check something":
            # Getting the ratelimit left
            ratelimit = self.get_ratelimit(message)
            if ratelimit is None:
                # The user is not ratelimited,you can add the XP or level up the user here

            else:
                # The user is ratelimited

今天的关于Python-为什么on_message会停止命令的工作?导致python停止工作的原因的分享已经结束,谢谢您的关注,如果想了解更多关于appium+python 运行报错:status":33,"value":{"message":"A new session coul...、BEGIN_MESSAGE_MAP 和END_MESSAGE_MAP() 这两个宏的具体实现与作用 (转)、Discord.py python message.content、discord.py 中 on_message 的冷却时间的相关知识,请在本站进行查询。

本文标签: