【发布时间】:2021-03-25 08:09:59
【问题描述】:
我为我的 discord.py 机器人创建了一个静音和取消静音命令,但是如果静音的成员重新进入,该角色将被删除,就好像他没有静音一样。我怎样才能使当你重新进入服务器时,它的角色在剩余的任期内一直由他担任?
import discord
from discord.ext import commands
import asyncio
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix="/", intents = intents)
logchannel = bot.get_channel(**********)
@bot.command()
async def mute(ctx, member:discord.Member, time:int):
muterole = discord.utils.get(ctx.guild.roles, id = *********)
await member.add_roles(muterole)
await asyncio.sleep(time * 60)
if muterole in member.roles:
await member.remove_roles(muterole)
return
else:
return
@bot.command()
async def unmute(ctx, member:discord.Member):
muterole = discord.utils.get(ctx.guild.roles, id = ******)
if muterole in member.roles:
await member.remove_roles(muterole)
return
else:
return
【问题讨论】:
标签: python discord.py