0
votes

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 :)

2
Have you tried the print trick? add a print under every line and see where it stops.Mikey
@Mikey yes, like I said I tried putting a print under the async def mute() to see if it even registered it. Nothing showed up though :/Nubz4evva
I'll try making it so the bot posts a message to the chat to see if that works, I'll test it at home!Nubz4evva
Do you have an on_message somewhere? If you do, this is for youMikey
yes thank you, I changed a client.event to a client.listen and it seemed to work. Mute unmute and kick are now working like a charm! Again, thank you for your help :)Nubz4evva

2 Answers

0
votes

You dont have a message variable. Instead of message write ctx.

So

 await message.channel.send(embed=embed)

should become

await ctx.channel.send(embed=embed)

To see the errors on your command prompt maybe first remove all you error commands. When I was making my bot, the error commands did not let me see errors on the command prompt. Maybe try that.

0
votes

I fixed it by changing a bot.event to a bot.listen! Make sure you keep your events limited and mostly use listens and commands. I think having more than 1 bot.event killed my code. Thanks to everyone for their input and I hope this fixes it for whoever comes from Google :)