简体   繁体   English

Discord.py bot 不响应静音命令

[英]Discord.py bot not responding to mute command

Im trying to make a mute command in discord.py and everything seems to be correct.我试图在 discord.py 中创建一个静音命令,一切似乎都是正确的。 Whenever i use the command then my bot doesn't respond with the message i've gave it, and it doesn't give the muted role.每当我使用该命令时,我的机器人都不会响应我给它的消息,也不会给出静音角色。 Here's the code:这是代码:

@commands.has_permissions(manage_roles=True)
async def mute(ctx, user: discord.Member, *, reason="No reason provided"):
    await user.mute(reason=reason)
    role = discord.utils.get(ctx.guild.roles, name="Muted")
    mute = discord.Embed(title=f"User {user.name}#{user.discriminator} has been muted. <a:m_verifyblack:850825891780100096>", color=0xF4D03F, description=f"Reason: {reason}\nBy: {ctx.author.mention}")
    await ctx.message.delete()
    await ctx.channel.send(embed=mute)
    await user.send(embed=mute)
@mute.error
async def mute_error(ctx, error):
    if isinstance(error, commands.MissingPermissions):
        await ctx.send("**:no_entry_sign: You cant do that!**")```

You appear to be missing the @client.command (if you did client = commands.Bot(command_prefix="prefix") at the beginning of the file under imports) at the beginning of the command.您似乎缺少client = commands.Bot(command_prefix="prefix")开头的@client.command (如果您在导入下的文件开头执行了client = commands.Bot(command_prefix="prefix") To fix this you would do要解决这个问题,你会这样做

import discord
from discord.ext import commands
from discord.ext.commands import MissingPermissions

client = commands.Bot(command_prefix="your_prefix")

@client.command(aliases=['m'])
@commands.has_permissions(manage_roles=True)
async def mute(ctx, user: discord.Member, *, reason="No reason provided"):
    role = discord.utils.get(ctx.guild.roles, name="Muted")
    mute = discord.Embed(title=f"User {user.name}#{user.discriminator} has been muted. <a:m_verifyblack:850825891780100096>", color=0xF4D03F, description=f"Reason: {reason}\nBy: {ctx.author.mention}")
    await user.mute(reason=reason)
    await ctx.message.delete()
    await ctx.channel.send(embed=mute)
    await user.send(embed=mute)

@mute.error
async def mute_error(ctx, error):
    if isinstance(error, commands.MissingPermissions):
        await ctx.send("**:no_entry_sign: You cant do that!**")

Also you seem to be using an outdated version of discord.py .此外,您似乎使用的是过时版本的 discord.py 。 Try switching to Pycord , which is a maintained fork of the now-deprecated discord.py.尝试切换到Pycord ,它是现已弃用的discord.py的维护分支。 I'm not quite sure what user.mute does, but hopefully I answered your question.我不太确定user.mute做了什么,但希望我回答了你的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM