Discord.py - 服务器静音用户

2023-12-01

我正在使用discord.py,但不使用命令,我无意改变。为了解释机器人的目标,我将使用一个小方案:

  1. 服务器成员发送如下消息: £Start @user#0001
  2. ping 到的用户的服务器静音(任何人都听不到他在任何语音聊天中的声音)
  3. 10秒过去
  4. 用户取消静音
  5. 1分钟通行证
  6. 用户被永久静音等等......

我知道这是一个巨魔机器人。但有时我们需要玩得开心......

我已经完成了最重要的部分,但我无法将用户静音。

# IMPORT
import discord
import time

# VARIABLES
token = "sorry but no"
client = discord.Client()

# CODE
@client.event
async def on_message(message):
    start = False

    # CODE
    if message.content.startswith("£Start <@!"):
        # Extract id from message
        message_content = message.content
        user_id = message_content.replace("£Start <@!", "")
        user_id = user_id.replace(">", "")

        rep_message = message
        await message.delete()
        start = True
        user_obj = await rep_message.guild.fetch_member(user_id)

        if str(user_obj.status) != "online" and start is True:  # if user is online and start is True:
            # loop
            while start:
                # NEED HELP HERE >> server mute = True
                time.sleep(10)
                # NEED HELP HERE >> server mute = False
                time.sleep(30)
        else:
            return
    else:
        return

client.run(token)

我希望我需要帮助的地方足够清楚。


Use Member.edit通过mute=True.

await user_obj.edit(mute=True)

您还应该使用await asyncio.sleep睡眠,以避免阻塞事件循环

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Discord.py - 服务器静音用户 的相关文章