【问题标题】:discord js how to check if message has a user id example: .ban [userid]discord js如何检查消息是否有用户ID示例:.ban [userid]
【发布时间】:2021-07-17 04:56:36
【问题描述】:

discord js 如何检查消息是否有用户 id 示例:.ban [userid]

示例: if (args[0] == 用户 ID) { 这将是用户 ID 功能 } 别的 { 这将是用户提及功能 }

【问题讨论】:

    标签: c# discord bots


    【解决方案1】:

    您可以尝试获取用户 id 并检查它是否是有效用户:

    
     // YOUR CODE
    
     // Assuming your Discord Client is named "client"
     let user = await client.users.fetch(args[0]).catch(() => null); // Fetch the user with the ID args[0]. If error -> output "null"
    
     if (user) {
    
      // Valid user id
    
     } else {
    
      // Invalid user id
    
     }
    
    
    

    确保您的函数异步使用await

    【讨论】:

      猜你喜欢
      • 2021-01-24
      • 2022-08-19
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 2019-04-16
      • 2021-07-18
      • 2019-11-23
      • 1970-01-01
      相关资源
      最近更新 更多