I am trying to create a mute command for my Discord bot. I typed all the code out and I am pretty sure it should be working. However whenever I type N?mute nothing happens and subsequently nothing shows up in my command prompt. No error message, no nothing. I tried putting a print just after the async def mute() and that didn't show up either.
I have the following code:
import random
import discord
from discord.ext import commands
import urllib.parse
import os
import pymongo
from pymongo import MongoClient
client = commands.Bot(command_prefix='N?')
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.command()
@commands.has_role(743487766796697720)
async def mute(ctx, member: discord.Member):
role = discord.utils.get(ctx.guild.roles, name="Muted")
guild = ctx.guild
if role not in guild.roles:
perms = discord.Permissions(send_messages=False, speak=False)
await guild.create_role(name="Muted", permissions=perms)
await member.add_roles(role)
embed=discord.Embed(title="User Muted!", description="**{0}** was muted by **{1}**!".format(member, ctx.message.author), color=0xff00f6)
await message.channel.send(embed=embed)
else:
await member.add_roles(role)
embed=discord.Embed(title="User Muted!", description="**{0}** was muted by **{1}**!".format(member, ctx.message.author), color=0xff00f6)
await message.channel.send(embed=embed)
@mute.error
async def mute_error(ctx, error):
if isinstance(error, commands.MissingRole):
embed=discord.Embed(title="Permission Denied.", description="You don't have permission to use this command.", color=0xff00f6)
await message.channel.send(embed=embed)
@mute.error
async def mute_error(ctx, error):
if isinstance(error, commands.BadArgument):
embed=discord.Embed(title="Permission Denied.", description="That is not a valid member.", color=0xff00f6)
await message.channel.send(embed=embed)
I tried making a kick command berore but after searching stackoverflow and dozen other websites to figure out why it didn't work, I gave up. Now I'm wondering why both client.commands have not worked so far. So far I have only used client.listen() and client.event() which both worked well. I don't know if it's simply an oversight or me doing something dumb but I'm at a loss right now. I'm fairly new to Discord.py so excuse my lack of skill :)