【问题标题】:How to get the sent message when a command is executed Discord.py执行命令时如何获取发送的消息 Discord.py
【发布时间】:2020-01-20 23:13:21
【问题描述】:

如果不和谐频道中的用户发送:

v!test Hello

如何让控制台打印

User#1321: Hello

我不确定如何实现这一点,感谢任何帮助。

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:
    import discord # using discord.py
    
    client = discord.Client() # creating a client instance
    
    @client.event # decorator to register function in the client events
    async def on_message(message): # this function gets called every time the client receives a message
        split_message = message.content.split(' ') # split the message into parts
        prefix = split_message[0]
        if prefix != 'v!test': # if the prefix doesn't match, we stop
            return
        rest = ' '.join(split_message[0:]) # this is everything except your v!test prefix
        print(f'{str(message.author)}: {rest}')
    
    client.run('your_token')
    

    【讨论】:

      猜你喜欢
      • 2020-12-02
      • 1970-01-01
      • 1970-01-01
      • 2021-06-17
      • 2021-03-24
      • 2021-02-08
      • 2022-06-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多