Why is this happening with discord.ext and replit? - python

I am trying to run discord.py but it is not working. This is the error
/home/runner/Mafia-Bot/venv/lib/python3.8/site-packages/nextcord/health_check.py:23: DistributionWarning: discord.py is installed which is incompatible with nextcord. Please remove this library by using `pip3 uninstall discord.py`
warn(message, DistributionWarning, stacklevel=0)
/home/runner/Mafia-Bot/venv/lib/python3.8/site-packages/nextcord/health_check.py:23: DistributionWarning: discord is installed which is incompatible with nextcord. Please remove this library by using `pip3 uninstall discord`
warn(message, DistributionWarning, stacklevel=0)
Traceback (most recent call last):
File "main.py", line 31, in <module>
async def Hello(ctx):
File "/home/runner/Mafia-Bot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 1262, in decorator
result = command(*args, **kwargs)(func)
File "/home/runner/Mafia-Bot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 1432, in decorator
raise TypeError('Callback is already a command.')
TypeError: Callback is already a command.
It is for a video game but is not connected.
Code:
import discord
from discord.ext import commands
import os
from discord import Member
from discord.ext.commands import MissingPermissions
from discord.ext.commands import has_permissions
intents = discord.Intents.default()
intents.members=True
client = commands.Bot(command_prefix="~$", intents=intents)
#######Events######
#client.event
async def on_ready():
print("Bot is up and ready!")
await client.change_presence(activity=discord.Game('ERLC'))
#client.event
async def on_member_join(member):
await member.send("Welcome to the mafia!")
######Commands#######
#client.command(pass_context=True)
#has_permissions(manage_roles=True)
#client.command()
async def Hello(ctx):
await ctx.send('Hi')
#client.command()
#has_permissions(kick_members=True)
async def kick(ctx, member: discord.Member, *, reason=None):
await member.kick(reason=reason)
await ctx.send(f"User {member} has been kicked.")
#kick.error
async def kick_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You do not have permissions to kick.")
#client.command()
#has_permissions(ban_members=True)
async def ban(ctx, member: discord.Member, *, reason=None):
await member.send("You have been banned")
await member.ban(reason=reason)
await ctx.send(f"User {member} has been banned.")
#ban.error
async def ban_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You do not have permissions to ban.")
client.run(os.getenv("TOKEN"))
Its probably easy to fix but I can't, I have only been coding for a year. I have to add alot of details but thats all I can say.

Related

discord.py: 'Bot' object has no attribute 'get' error

i'm trying to make my first discord bot in python. It worked well, untill I wanted to add function, when bot greets new member on specific channel.
Here is my code:
import discord
from discord.ext import commands
from discord.ext.commands import has_permissions
intents = discord.Intents.all()
client = commands.Bot(command_prefix='.',intents=intents)
#client.event
async def on_ready():
await client.change_presence(activity=discord.Game(name="chess with your mum"))
print("Bot is ready")
#client.event
async def on_member_join(member):
channel = client.get.channel(828249420784205824)
await channel.send(f'{member} dolaczyl do serwera!') #in english: "joined the server!"
#client.event
async def on_member_leave(member):
channel = client.get.channel(828249420784205824)
await channel.send(f'{member} opuscil serwer!') #in english: "leaved the server!"
#client.command()
#has_permissions(ban_members = True)
async def ban(ctx, member : discord.Member, *, reason=None):
await member.ban(reason=reason)
await ctx.send(f'Uzytkownik {member} dostal bana!') #in english: "got banned"
#client.command()
#has_permissions(kick_members = True)
async def kick(ctx, member : discord.Member, *, reason=None):
await member.kick(reason=reason)
await ctx.send(f'Uzytkownik {member} zostal wyrzucony!') #in english: "got kicked"
client.run('TOKEN')
And error:
2022-12-17 20:21:24 ERROR discord.client Ignoring exception in on_member_join
Traceback (most recent call last):
File "/home/runner/Bot/venv/lib/python3.8/site-packages/discord/client.py", line 409, in _run_event
await coro(*args, **kwargs)
File "main.py", line 16, in on_member_join
channel = client.get.channel(828249420784205824)
AttributeError: 'Bot' object has no attribute 'get'
I would be very happy if anyone can help me. Thanks
I think you're looking for the client.get_channel method instead of client.get.channel, which doesn't exist.

Discord bot kick command error message python

So I found this code for a kick command and I would like to know how to make it so if the person who sent the kick command doesn't have permissions it replies to the user and says that they don't have the right permissions.
#commands.has_permissions(administrator=True)
async def kick(ctx, user : discord.Member,*,reason):
await user.kick(reason=reason)
await ctx.send(f'{user} kicked for {reason} by {ctx.author}')
That's the code
This should send a message telling users that they don't have permissions if they try to use the command without the proper roles
from discord.ext.commands import MissingPermissions
#Import this at the top of your code
#Write the error handler below the code where you define the kick command
#kick.error
async def kick_error(self, ctx, error):
if isinstance(error, MissingPermissions):
await ctx.send("You don't have permission to kick members.")
For me I would write:
import discord
from discord.ext import commands
from discord.ext.commands import MissingPermissions
client = commands.Bot(command_prefix=("prefix"))
#client.command()
#commands.has_role("Administrator")
async def kick(self, ctx, member : commands.MemberConverter, *, reason=None):
await member.kick(reason=reason)
await ctx.send(f"{member} has been kicked, reason: {reason}")
#kick.error
async def kick_error(self, ctx, error):
if isinstance(error, MissingPermissions):
await ctx.send("You don't have permission to kick members.")

unexpected unindent (Discord.py)

There is a "unexpected unindent" in this code for Discord.py the code is:
#client.command()
async def kick(ctx, member: discord.Member, reason=None):
await member.kick(reason=reason)
await ctx.send("The Member Was Kicked.")
the full code:
import os
import discord
from discord.ext import commands
from discord.ext.commands import Bot
from discord.ext.commands import has_permissions, MissingPermissions, is_owner
import json
client = commands.Bot(command_prefix='.')
status=discord.Status.idle
#client.command()
async def ban(ctx, member: discord.Member, reason=None):
await member.ban(reason=reason)
await ctx.send("The Member Was Banned.")
#client.command()
async def kick(ctx, member: discord.Member, reason=None):
await member.kick(reason=reason)
await ctx.send("The Member Was Kicked.")
#client.event
async def on_ready():
print('we have logged in as {0.user}'.format(client))
my_secret = os.environ['Token']
client.run(my_secret)
Bugs
Line 16
#client.command()
async def kick(ctx, member: discord.Member, reason=None):
await member.kick(reason=reason)
await ctx.send("The Member Was Kicked.")
It is clearly visible that the first line is not indented correctly.
line 24
#client.event
async def on_ready():
print('we have logged in as {0.user}'.format(client))
Here, the third line is not indented correctly.
Fixing the indentation, your code should look like the following
import os
import discord
import json
from discord.ext import commands
from discord.ext.commands import Bot
from discord.ext.commands import has_permissions, MissingPermissions, is_owner
client = commands.Bot(command_prefix='.')
status = discord.Status.idle
#client.command()
async def ban(ctx, member: discord.Member, reason=None):
await member.ban(reason=reason)
await ctx.send("The Member Was Banned.")
#client.command()
async def kick(ctx, member: discord.Member, reason=None):
await member.kick(reason=reason)
await ctx.send("The Member Was Kicked.")
#client.event
async def on_ready():
print('we have logged in as {0.user}'.format(client))
my_secret = os.environ['Token']
client.run(my_secret)
This is not a discord.py issue.
Your indentation in flawed
Line 16
#client.command()
async def kick(ctx, member: discord.Member, reason=None):
await member.kick(reason=reason)
await ctx.send("The Member Was Kicked.")
instead it should be
#client.command()
async def kick(ctx, member: discord.Member, reason=None):
await member.kick(reason=reason)
await ctx.send("The Member Was Kicked.")
If this doesnt fix your problem , check if you used tabs instead of spaces or vice versa.

How do I fix this discord ban bot using python

I'm trying to make a discord bot that bans a user when I say .ban #Example_User, but when I run the code no errors pop up but then when I try to use the error appears, I've been using this tutorial https://www.youtube.com/watch?v=THj99FuPJmI, and here is my code and error below:
import discord
import random
import os
from discord.ext import commands
client = commands.Bot(command_prefix = '.')
#client.event
async def on_ready():
print("Bot is ready")
#client.command()
async def kick(ctx, member : discord.member, * , reason=None):
await member.kick(reason=reason)
#client.command()
async def ban(ctx, member : discord.Member, *, reason=None):
await member.ban(reason=reason)
client.run(os.getenv('TOKEN'))
and here is my error

Discord.py Welcome/Removed messages in chat

So I am trying to make my bot leave welcome and removed messages using discord.py.
import discord
from discord.ext import commands
import random
client = commands.Bot(command_prefix = '.')
#client.event
async def on_member_join(ctx, *, member):
channel = member.server.get_channel("channel id")
fmt = 'Welcome to the {1.name} Discord server, {0.mention}'
await ctx.send_message(channel, fmt.format(member, member.server))
#client.event
async def on_member_remove(ctx, *, member):
channel = member.server.get_channel("channel id")
fmt = '{0.mention} has left/been kicked from the server.'
await ctx.send_message(channel, fmt.format(member, member.server))
client.run('client id')
The error
File "C:\python\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
TypeError: on_member_join() missing 1 required keyword-only argument: 'member'
comes up.
I am not sure why it isn't working. I have very little experience with it, so I am not sure what I am doing wrong. Could anyone tell me what I am missing?
#client.event
async def on_member_join(member):
await client.get_channel(idchannel).send(f"{member.name} has joined")
#client.event
async def on_member_remove(member):
await client.get_channel(idchannel).send(f"{member.name} has left")
On event you can't get ctx, because it isn't a command, who must write. It is event
#client.event
async def on_member_join(member):
await client.get_channel(idchannel).send(f"{member.name} has joined")
#client.event
async def on_member_remove(member):
await client.get_channel(idchannel).send(f"{member.name} has left")
also keep in mind that idchannel is int, not string

Categories

Resources