dolfies / discord.py-self

A fork of the popular discord.py for user accounts.
https://discordpy-self.rtfd.io/en/latest/
MIT License
665 stars 155 forks source link

Bot and Client in one environment #530

Closed Walterwhite233 closed 11 months ago

Walterwhite233 commented 1 year ago

Summary

Bot and client in one environment won't start

Reproduction Steps

Hello, I'm trying to start a bot and a client in different processes (first I tried it in two different files). But I keep getting an error message from the bot. Token is 100% correct. With other libraries he goes.

Code

Client.py:

import discord

class MyClient(discord.Client):
    async def on_ready(self):
        print('Logged on as', self.user)

    async def on_message(self, message):
        # only respond to ourselves
        if message.author != self.user:
            return

        if message.content == 'ping':
            await message.channel.send('pong')

client = MyClient()
client.run('Token')

------------------------------

Bot.py:

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix='>', self_bot=True)

@bot.command()
async def ping(ctx):
    await ctx.send('pong')

bot.run('Token')

Expected Results

Bot log in

Actual Results

raise LoginFailure('Improper token has been passed') from exc

discord.errors.LoginFailure: Improper token has been passed

System Information

Checklist

Additional Information

No response

anpco commented 1 year ago

I have the same issue

anpco commented 1 year ago

I tried to post a get user info from Postman, it also returned 401 Unauthorized. Maybe it is from Discord

Walterwhite233 commented 1 year ago

unfortunately I haven't found a solution until today... except to run two scripts =D

dolfies commented 11 months ago

If you are trying to use discord.py-self and upstream discord.py in the same project, you must use the renamed branch. This is because the two libraries share the same namespace (i.e. import discord) making them interfere with each other when used in the same environment.