本文介绍了Discord.py-服务器静音用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用discord.py,但未使用命令,因此无意进行更改。为了解释机器人的目标,我将使用一个小方案:
I'm using discord.py but not using command and I have no intention in changing. To explain the goal of the bot I will use a small scheme:
- 服务器成员发送如下消息:£Start @ user#0001
- ping通的用户使服务器静音(没人能在任何语音聊天中听到他的声音)
- 10秒过去
- 用户取消静音
- 1分钟通过
- 用户静音,以此类推,直到永远……
- server member sends a message like this: £Start @user#0001
- pinged user gets server muted (no one can hear him in any voice chat)
- 10 seconds pass
- user gets unmuted
- 1-minute passes
- user gets muted and so on forever...
我知道这是一个Troll机器人。但是我们需要在某个时候玩得开心...
I know this is a Troll bot. But we need to have fun sometime...
我已经做了最大的一部分,但是我在使用户静音方面遇到了麻烦。
I have already done the biggest part, but I'm having trouble muting the user.
# 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)
我希望在需要帮助的地方足够清楚。
I hope is clear enough where I need help.
推荐答案
使用通过 mute = True
。
await user_obj.edit(mute=True)
您还应该使用 await asyncio.sleep
进行睡眠,以避免阻塞事件循环
You should also be using await asyncio.sleep
to sleep, to avoid blocking the event loop
这篇关于Discord.py-服务器静音用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!