Yasir
Yasir

Reputation: 19

NameError: name 'bot' is not defined

I'm currently developing a discord bot and ran into an issue where the word bot isn't 'defined'.

I've already tried replacing bot with client, however, that creates more issues. This is my code:

@bot.command()
async def kick(ctx, user: discord.Member, * , reason=None):
    if user.guild_permissions.manage_messages:
        await ctx.send('I cant kick this user because they are an admin/mod.')
    elif ctx.author.guild_permissions.kick_members:
        if reason is None:
            await ctx.guild.kick(user=user, reason='None')
            await ctx.send(f'{user} has been kicked by {ctx.message.author.mention}')
        else:
            await ctx.guild.kick(user=user, reason=reason)
            await ctx.send(f'{user} has been kicked by {ctx.message.author.mention}')
    else:
        await ctx.send('You do not have permissions to use this command.')

Upvotes: 0

Views: 11032

Answers (1)

creed
creed

Reputation: 1427

You need to create an instance of bot for it to run correctly:

import discord
from discord.ext import commands

bot = discord.ext.commands.Bot(command_prefix = "your_prefix");

bot.run("your_token")

Upvotes: 2

Related Questions