You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Discordrb中获取发送斜杠命令用户的User ID

在discordrb中获取斜杠命令发送者的user_id

在discordrb的斜杠命令交互上下文(Interaction对象)里,你可以通过以下方式获取发送者的user_id:

  • 先通过interaction.user拿到发送命令的用户对象
  • 再调用该对象的id属性,即可得到对应的user_id

示例代码:

bot.application_command(:example_cmd) do |interaction|
  sender_id = interaction.user.id
  interaction.respond("你的用户ID是:#{sender_id}")
end

这里的interaction.user对应discord.py里的interaction.author,只是属性命名不同,作用完全一致。

内容的提问来源于stack exchange,提问作者Droid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 06:24:49