【问题标题】:(Discord selfbot) Is there anyway to response if 'hi' in someone message(Discord selfbot)如果有人消息中的“嗨”,无论如何都要回复
【发布时间】:2022-06-13 12:17:34
【问题描述】:

如果“hi”出现在某人的消息中,是否有办法让 selfbot 响应“hello”? 喜欢

A:喂?有人在这里吗? 机器人:你好

机器人响应,因为“hi”在 A 的消息中。 我认为这是不可能的,因为我尝试了许多 Discord selfbot 库并且没有库工作(Python)

【问题讨论】:

  • 自我机器人反对 Discord Terms of Services
  • 我投票结束这个问题,因为 selfbots 反对 TOS
  • 我知道 selfbot 违反 TOS,但我创建它只是为了好玩。

标签: discord bots


【解决方案1】:

您使用的是哪个库?

我用discord.js (Javascript) 制作了一个不和谐的机器人,每次有人在你的不和谐服务器上讲话时,你都可以收到一个事件,然后根据消息的内容做出响应。

首先你启动你的 discord 客户端(Intent 可能会根据你想要做的事情而有所不同):

     const discordClient =  new Client({ intents: [Intents.FLAGS.DIRECT_MESSAGES, Intents.FLAGS.GUILD_MESSAGES] })

然后想法是获取每条新消息的内容并正确回答,一旦您创建了您的不和谐客户端,您将需要设置一个像这样的事件监听器:

    discordClient.on('messageCreate', message => {
        const content = messageReceived.content.toLocaleLowerCase()
        if (content === 'hi') {
            messageReceived.channel.send("hello, I'm a bot!")
        }
    })

别忘了使用您的 discord 机器人密钥登录

    const discordKey = "YOUR DISCORD BOT KEY"
    discordClient.login(discordKey)

您还可以查看我的机器人 here 的存储库。

对于您的用例,您可能希望主要关注discord.ts 中的某些部分。

希望这会有所帮助。

【讨论】:

  • 我在 Python 中使用 Discum 和 Discord.py。有没有办法用 Python 做到这一点?
【解决方案2】:

以下是在node.js 中使用discord.js 的一些基本示例。

简单回复

要发送响应,只需检查用户的消息是否包含您希望机器人响应的所需输入。

if(message.content.toLowerCase().includes("ping") {
     message.reply("Pong!")
}

多个响应

这是响应多个输入的更有效的方法。这包括使用数组。

const array = [
     "hello",
     "hola",
     "bonjour"
]

if(array.some(word => message.content.toLowerCase().includes(`${word}`)) {
     message.reply("Hello!")
}

【讨论】:

    【解决方案3】:

    这是代码

    ---从这里开始:---

    // type `await lib.` to display API autocomplete
    const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
    
    // Only respond to messages containing "hi", "hey", "hello", or "sup"
    if (context.params.event.content.match(/hi|hey|hello|sup/i)) {
      let messageContent = context.params.event.content.match(/hi|hey|hello|sup/i);
    
      await lib.discord.channels['@0.3.0'].messages.create({
        channel_id: context.params.event.channel_id,
        content: `${messageContent[0]} to you too ?`,
        message_reference: {
          message_id: context.params.event.id
        }
      });
    }
    

    --结束--

    Image of code


    我建议使用 autocode.com,它会真正帮助您编码生活。我自己用。

    这是一个小指南https://autocode.com/guides/how-to-build-a-discord-bot/

    【讨论】:

      【解决方案4】:

      如果你禁止使用 discord selfbot,那不是我的错

      from discord.ext import commands
      
      client = commands.Bot(
        command_prefix='-',
        self_bot=True,
        help_command=None
      )
      
      @client.event
      async def on_message(message):
       if message.author == client.user:
            return
      
       if message.content == 'Hello!':
                  await message.channel.send("Hi how your day!")
      
      client.run('user token', bot=False)
      

      【讨论】:

        猜你喜欢
        • 2020-06-02
        • 1970-01-01
        • 1970-01-01
        • 2021-07-01
        • 2023-04-10
        • 2019-11-05
        • 2017-12-24
        • 1970-01-01
        • 2021-07-24
        相关资源
        最近更新 更多