I would appreciate if anyone out there could help me.
I wanted to code a bot for a esports team, which does have a ticket included, on pycharm on my computer actually everything works fine, but when i then want to host it on replit it doesnt work. I have made the ticket with discord-components and as the button is clicked, the bot thinks, but does never send the messege and goes on with the code. But on my other replit file I have another ticket, but that does work just fine.
Does someone have an idea what could have gone wrong?
#client.command()
async def tryout(ctx):
server = client.get_guild(879321194506121247)
tryouter = get(server.roles, name="Tryouter")
embed_tryout = discord.Embed(title="Tryout",
description="*Start your tryout right now, to join HOC-Esports and start your clash royale esports journey*",
color=discord.Color.from_rgb(244, 246, 246))
embed_tryout.add_field(name="What we offer:",
value="• 4-5 scrims per week\n• A good organised team with engaged managers\n• Custom HOC logo + banner",
inline=False)
embed_tryout.add_field(name="What we demand from you:",
value="• You are engaged to improve yourself\n• You aren't toxic",
inline=False)
embed_tryout.add_field(name="Informations to the tryout""Infos zum Tryout",
value=f"You will make a bo5 against a {tryouter.mention}, who will rate your skill decide if you fit in our team or not",
inline=False)
await ctx.send(embed=embed_tryout, components=[
[Button(label="🎫 start tryout", style=1, custom_id="button1")]
])
#client.event
async def on_button_click(interaction):
if interaction.custom_id == "button1":
pass
else:
return
guild = interaction.guild
tryouter = get(guild.roles, name="Tryouter")
category = client.get_channel(997078909071929434)
await interaction.send(content="You just started a tryout", ephemeral=True)
benutzer = str(interaction.user)
user_letters = len(benutzer)
username = benutzer[:user_letters - 4]
ticket_channel = await guild.create_text_channel(name=f"Tryout of {username}", category=category)
user = interaction.author
tryoutrole = get(guild.roles, name= "Tryout")
visitorrole = get(guild.roles, name="Besucher")
esports_role = get(guild.roles, id=917100410400014426)
await user.add_roles(tryoutrole)
await user.remove_roles(besucherrolle)
await ticket_channel.set_permissions(user, view_channel=True, read_message_history=True, read_messages=True,
add_reactions=True, embed_links=True, attach_files=True,
use_external_emojis=True)
await ticket_channel.send(
f"Welcome {interaction.user.mention}. You just started a tryout.\nA {tryouter.mention} will take care of you.\nPlease send meanwhile your friendlink and your profile right here\nIf you don't want to make the tryout anymore, just close the ticket.",
components=[
Button(label="🔒 close ticket", style=2, custom_id="button2")
])
interaction2 = await client.wait_for("button_click", check=lambda i: i.custom_id == "button2")
await interaction2.send(content="You just closed the ticket", ephemeral=True)
time.sleep(5)
await ticket_channel.delete()
await user.remove_roles(tryoutrole)
if esports_role in user.roles:
return
await user.add_roles(visiterrole)
Related
Im trying to make a public bot, and i would want this ticket system witha logging channel it already has a logging channel but how can i modify this to make a command that sets the logging channel?
# --- Ticket Open ---
#client.command()
#commands.guild_only()
async def ticket(ctx):
if ctx.channel.type != discord.ChannelType.private:
channels = [str(channel) for channel in client.get_all_channels()]
if f'ticket-{ctx.author.id}' in channels:
await ctx.message.delete()
else:
ticket_channel = await ctx.guild.create_text_channel(f'ticket-{ctx.author.id}')
await ticket_channel.set_permissions(ctx.guild.default_role, send_messages=False, read_messages=False)
await ticket_channel.set_permissions(ctx.author, send_messages=True, read_messages=True, add_reactions=True, embed_links=True, attach_files=True, read_message_history=True, external_emojis=True)
embed = discord.Embed(color=10181046, description=f'Please enter the reason for this ticket, type `-close` if you want to close this ticket.')
embed.set_thumbnail(url='')
await ticket_channel.send(f'{ctx.author.mention}', embed=embed)
await ctx.message.delete()
logchannel = await client.fetch_channel('850364625479532545')
embed = discord.Embed(title="Ticket Created",
description="",
color=discord.Colour.green())
embed.add_field(name=f'**By:** {ctx.author}',value= f'**ID:** {ctx.author.id}')
await logchannel.send(embed=embed)
#--- Ticket Close ---
#client.command()
#commands.guild_only()
async def close(ctx):
print(f'{ctx.author} | {ctx.author.id} -> {client.command_prefix}close')
if ctx.channel.type != discord.ChannelType.private:
admin_roles = [834126146215477348,835608325273157733,838859643224326144,835582821221138472,835914273402126376]
if ctx.channel.name == f'ticket-{ctx.author.id}':
await ctx.channel.delete()
elif admin_roles and 'ticket' in ctx.channel.name or ctx.author.id in administrator_ids and 'ticket' in ctx.channel.name:
await ctx.channel.delete()
else:
await ctx.message.delete()
logchannel = await client.fetch_channel('850364625479532545')
embed = discord.Embed(title="Ticket Closed",
description="",
color=discord.Colour.red())
embed.add_field(name=f'**By:** {ctx.author}',value= f'**ID:** {ctx.author.id}')
await logchannel.send(embed=embed)
Tip: if you want to create a public bot don't use handwritten channel id, you'd better save to file for all servers in json file and set it with command.
For example this:
{
"server identifier": "system channel identifier",
...
}
I don't know what's wrong with the code.
I'm trying to add a few subcommands to my code to make everything clearer.
Unfortunately, I have the problem that certain sections of code are simply not executed.
My Code:
#commands.group(invoke_without_command=True)
async def server(self, ctx):
created = ctx.guild.created_at
x = re.search("^.*:", str(created))
x = x.group()
x = x[:-6]
me = ctx.guild
embed = discord.Embed(title = f"Information about ``{ctx.guild}``", description=me.description, color = 0xf7fcfd, timestamp=ctx.message.created_at)
embed.add_field(name="__Information__", value=f"**Owner:** {me.owner}\n**Name:** {me.name}\n**ID:** {me.id}\n**Region:** {me.region}\n**Created at:** {x}", inline=False)
embed.add_field(name="__Server Information__", value=f"**Member**: {len(me.members)}\n**Roles:** {len(me.roles)}\n**Max Emojis:** {me.emoji_limit}\n**Emojis:** {len(me.emojis)}", inline=False)
embed.add_field(name="__Channel Information__", value=f"**Text-Channel:** {str(len(me.text_channels))}\n**Voice-Channel:** {str(len(me.voice_channels))}\n**AFK-Channel:** ``{me.afk_channel}``\n**AFK-Timeout:** ``{me.afk_timeout}sec``")
embed.set_footer(text=f"{ctx.message.author.name}", icon_url=ctx.message.author.avatar_url)
embed.set_thumbnail(url=me.icon_url)
embed.set_image(url=me.banner_url)
await ctx.send(embed=embed)
# SERVER AVATAR
#server.command()
async def avatar(self, ctx):
if not ctx.guild.icon:
embed = discord.Embed(title="Server has no avatar!", color=0xf7fcfd)
return await ctx.send(embed=embed)
else:
embed = discord.Embed(title=f"Avatar of {ctx.guild.name}", color=0xf7fcfd)
embed.set_image(url=ctx.guild.icon_url_as(size=1024))
await ctx.send(embed=embed)
# SERVER BANNER
#server.command()
async def banner(self, ctx):
if not ctx.guild.banner:
embed = discord.Embed(title="Server has no banner!", color=0xf7fcfd)
return await ctx.send(embed=embed)
else:
embed = discord.Embed(title=f"Banner of {ctx.guild.name}", color=0xf7fcfd)
embed.set_image(url=ctx.guild.banner_url_as(format='png'))
await ctx.send(embed=embed)
The problem is that the command ?server avatar does not provide any output. The commands ?server and ?server banner work perfectly.
Am I using the subcommands incorrectly or why do I get no output?
The reason why it didn't work is that I already had another command called avatar. The Bot would always take the command (avatar) instead the subcommand (server avatar).
I switched to cogs yesterday so my code looks cleaner. Since then, all commands have broken. If you send t!profile it will send the message twice. I figured out that the problem has something to with the filter that I created.
if getImmunityValue == 0:
for word in getWord:
if getMutedValue == 0:
message.content = message.content.lower()
if message.content.count(''.join(word)) > 0:
id = message.author.id
curs.execute('SELECT channelID FROM getchannel')
getChannelID = curs.fetchone()[0]
channel = self.client.get_channel(getChannelID)
curs.execute('SELECT strike FROM user WHERE userID = (%s)', (id,))
getstrike = curs.fetchone()[0]
curs.execute(f'UPDATE user SET strike = {getstrike + 1} WHERE userID = {id}')
db.commit()
await message.delete()
await message.channel.send(f'{message.author.mention} Bitte benutzte kein Schimpfwoerter. Falls du weiter machen solltest, wirst du gebannt oder gemutet!')
Embed = discord.Embed(
title=f'{getstrike}x strike(s) from {message.author}',
color=discord.Colour.red(),
timestamp=self.datetime.utcnow()
)
Embed.add_field(name='Blacklist Wort:', value=message.content, inline=False)
Embed.add_field(name='Channel-ID:', value=message.channel.id, inline=False)
Embed.add_field(name='Channel:', value=message.channel, inline=False)
await channel.send(embed=Embed)
await self.client.process_commands(message)
So the problem is the await self.client.process_commands(message) I don't know why, but that fixes it.
I was making a discord bot in Python, and when i wanted to run it - the error occurred - expected an indented block, I'll show some code :
I tried to move some things but it didn't work. Also I'm completely new to Python and I have done some things with the tutorials on YouTube. Help me please.
import discord
import random
client = discord.Client()
#client.event
async def on_ready():
await client.change_presence(status=discord.Status.idle, activity=discord.Game('?help'))
print('Bot jest online.')
#client.event
async def on_message(message):
id = client.get_guild(586513031765426198)
if message.content.find("?ping") != -1:
await message.channel.send("Pong! Jestem gotowy do użytku!")
if message.content.find("?plany") != -1:
await message.channel.send("Mam zamiar dodać do bota dużo komend!")
if message.content == "?rzut-monetą":
variable = [
'Orzeł!',
'Reszka!',]
await message.channel.send(random.choice(variable))
if message.content == "?pomoc":
embed = discord.Embed(title="Komendy!", description="Znajdziecie tutaj wszystkie komendy.", colour=discord.Colour.red())
embed.add_field(name="!ping", value="Sprawdza, czy bot jest teraz online.", inline=False)
embed.add_field(name="!info", value="Daje informacje o bocie.", inline=False)
embed.add_field(name="!plany", value="Pokazuje plany na przyszłość dotyczące bota.", inline=False)
embed.add_field(name="!pomoc", value="Pokazuje tą wiadomość.", inline=False)
embed.add_field(name="!rzut-monetą", value="Losuje pomiędzy orłem a reszką. Świetne do rozstrzygania sporów.", inline=False)
await message.channel.send(content=None, embed=embed)
if message.content == "?info":
embed = discord.Embed(title="Informacje!", description="Krótkie info o bocie.", colour=discord.Colour.blue())
embed.add_field(name="Autor", value="Pomi ;3#2203", inline=False)
embed.add_field(name="O bocie", value="Zadanie tego bota to głównie rozrywka, ale ma też wbudowanego auto-moderatora do polskich przekleństw.", inline=False)
await message.channel.send(content=None, embed=embed)
one line under the ?info command the first embed is showing on a red background. What could this mean?
You're missing an indented block on the last if
Where you have:
...
if message.content == "?info":
embed = discord.Embed(title="Informacje!", description="Krótkie info o bocie.", colour=discord.Colour.blue())
embed.add_field(name="Autor", value="Pomi ;3#2203", inline=False)
embed.add_field(name="O bocie", value="Zadanie tego bota to głównie rozrywka, ale ma też wbudowanego auto-moderatora do polskich przekleństw.", inline=False)
await message.channel.send(content=None, embed=embed)
Replace with:
...
if message.content == "?info":
embed = discord.Embed(title="Informacje!", description="Krótkie info o bocie.", colour=discord.Colour.blue())
embed.add_field(name="Autor", value="Pomi ;3#2203", inline=False)
embed.add_field(name="O bocie", value="Zadanie tego bota to głównie rozrywka, ale ma też wbudowanego auto-moderatora do polskich przekleństw.", inline=False)
await message.channel.send(content=None, embed=embed)
Note. If you intended to execute only part of that block, unindent whatever you don't care about the condition.
elif cmd_args[0].upper() == "D!CREATECHANNEL":
everyone = discord.PermissionOverwrite(read_messages=False, send_messages=False, create_instant_invite=False, manage_channel=False, manage_permissions=False, manage_webhooks=False, send_TTS_messages=False, manage_messages=False, embed_links=False, attach_files=False, read_message_history=False, mention_everyone=False, use_external_emojis=False, add_reactions=False)
Member = discord.PermissionOverwrite(read_messages=True, send_messages=True, create_instant_invite=False, manage_channel=False, manage_permissions=False, manage_webhooks=False)
server = message.server
await client.create_channel(server, cmd_args[1], (server.default_role, everyone), (discord.utils.get(message.server.roles, name='Member'), Member))
pass
the bot makes a channel like this https://cdn.discordapp.com/attachments/471468848718020623/473202969492455425/gng.PNG (the command rn that makes this is D!createchannel name)
what i want the bot to do is do this https://cdn.discordapp.com/attachments/471468848718020623/473202968989138945/Capturegbgg.PNG (for it to do this i want the command to be D!createchannel name #The Golden Atlas [16-A]) I just don't know how to make it do it mabey I am being dumb and don't see it but I really need this help its the last bit of my bot that needs work
You can get all of the mentioned members from message.member, then build a (target, PermissionOverwrite) tuple for each of them and pass that to create_channel.
elif cmd_args[0].upper() == "D!CREATECHANNEL":
everyone = discord.PermissionOverwrite(read_messages=False, send_messages=False, create_instant_invite=False, manage_channel=False, manage_permissions=False, manage_webhooks=False, send_TTS_messages=False, manage_messages=False, embed_links=False, attach_files=False, read_message_history=False, mention_everyone=False, use_external_emojis=False, add_reactions=False)
Member = discord.PermissionOverwrite(read_messages=True, send_messages=True, create_instant_invite=False, manage_channel=False, manage_permissions=False, manage_webhooks=False)
server = message.server
member_perms = [(mentioned, Member) for mentioned in message.mentions]
await client.create_channel(server, cmd_args[1], (server.default_role, everyone), (discord.utils.get(message.server.roles, name='Member'), Member), *member_perms)