Apster137
Apster137

Reputation: 65

Discord Python Bot unable to set prefix

Okay so I am designing a Discord bot in Python, am pretty new though. I was trying to get it to join a voice channel so I did some research and came up with the following, I cut out the irrelevant part of the bot so this is just the part with the voice connection. It says: undefined name "commands" over the line that should set the prefix:

import discord
import os
import requests
import json
import random

client = discord.Client()
client = commands.Bot(command_prefix='!')

@client.event
async def on_ready():
    print("Eingeloggt als {0.user}".format(client))

@bot.command()
async def join(ctx):
    channel = ctx.author.voice.channel
    await channel.connect()
@bot.command()
async def leave(ctx):
    await ctx.voice_client.disconnect()

client.run(os.getenv("TOKEN"))

Upvotes: 0

Views: 188

Answers (1)

Axisnix
Axisnix

Reputation: 2907

You must use from discord.ext import commands

import discord
import os
import requests
import json
import random
from discord.ext import commands

bot = commands.Bot(command_prefix='!')

@bot.event
async def on_ready():
    print("Eingeloggt als {0.user}".format(client))

@bot.command()
async def join(ctx):
    channel = ctx.author.voice.channel
    await channel.connect()
@bot.command()
async def leave(ctx):
    await ctx.voice_client.disconnect()

bot.run(os.getenv("TOKEN"))

Upvotes: 1

Related Questions