【问题标题】:Mute command with database discord.py使用数据库 discord.py 静音命令
【发布时间】:2022-01-13 18:24:58
【问题描述】:

因此,例如,在常规静音命令中,机器人正在获取更新,静音命令留在最后一点,永远不会取消用户静音!所以我创建了一个数据库,并将当前静音的 user_id 和日期时间存储为最终取消静音时间还存储了公会的 id

例如,当我开始更新时,静音会保存到数据库中,以便稍后从 on_ready 事件中提取。然后我拉取值,然后执行discord.utils.sleep_until(dateime #aka the final unmute time),完成后取消用户静音。

问题来了:我怎样才能得到存储在数据库中的公会ID,并从数据库中取出公会中的静音角色(因为服务器又名“ctx”不再是东西)?

语言 - Python, 数据库——mysql

+----------------------------------------
|user1 |datetime(of the unmute)|guild_id|
+----------------------------------------

mute - inserts the above info^^^

def on_ready():
     print("ready")
     selects the values
     discord.utils_sleep_until(datetime of unmute)
     take away role in guild

如果我目前的方法不是最好的,我当然愿意接受更好的建议。

【问题讨论】:

  • 请包含一些代码,以便我们可以看到您到目前为止所做的事情!
  • 这更像是一个概念性问题,我们不想在不知道这种方式是否可行的情况下进行编码,但类似于上面的内容^
  • How can I get the server's/guild's id(which is stored in the database) and take away the muted role in the guild gotten from the database(since the server aka "ctx" is no longer a thing!) - 不是概念问题。它是关于如何编写代码/如何工作的。如果您在将角色授予成员时存储了guild,您确实可以从数据库中获取它。因此,我们需要知道您的代码的外观/您如何存储所有内容。

标签: mysql discord.py


【解决方案1】:

尝试实现这个:

# load guild
guild = client.get_guild(guild_id)

# load member of the guild
member = client.get_member(member_id)

# remove role from the member
member.remove_roles([mute_role])

client.get_guild 将与 Guild.get_member 一样将不和谐的公会数据加载到内存中。 您只需要使用您想要定位的公会/成员的 id 来获取它们。

【讨论】:

  • 老兄,谢谢!
  • 请注意,如果成员没有被机器人缓存,您可能需要使用await guild.fetch_member()
  • Alr,谢谢!是的 get_guild 返回一个 NoneType 即使值是一个 int 并且存在是 on
猜你喜欢
  • 2020-10-28
  • 1970-01-01
  • 1970-01-01
  • 2018-06-07
  • 2021-09-02
  • 2020-06-15
  • 2022-01-19
  • 1970-01-01
相关资源
最近更新 更多