The button doesn't respond if no one has clicked it in 3 minutes.
I saw that it was something with timeout but I don't know where to place it.
My code:
#Tickets
class Menu(discord.ui.View):
def __init__(self):
super().__init__()
self.value = None
#discord.ui.button(label="📥 Ticket", style=discord.ButtonStyle.grey)
async def menu1(self, interaction: discord.Interaction, button: discord.ui.Button):
with open("open_channels_user_id.json", "r") as f:
data = json.load(f)
user_id = data["user_id"]
if user_id != interaction.user.id:
admin_role = discord.utils.get(interaction.guild.roles, name="hulpje")
category = discord.utils.get(interaction.guild.categories, name='Ticket')
overwrites = {interaction.guild.default_role: discord.PermissionOverwrite(read_messages=False),
interaction.guild.me: discord.PermissionOverwrite(read_messages=True),
interaction.user: discord.PermissionOverwrite(read_messages=True),
admin_role: discord.PermissionOverwrite(read_messages=True)}
new_ticket = await interaction.guild.create_text_channel(f'Ticket- {interaction.user.name}', category=category, overwrites=overwrites)
channel = client.get_channel(new_ticket.id)
embed = discord.Embed(title=f'Ticket- {interaction.user.name}', description="Goed dat je een ticket opent. \n Stuur alvast wat informatie zodat het makkelijker is voor het staff team.", color=0x004BFF)
await channel.send(embed=embed)
await interaction.response.send_message(f"Ticket is geopen met de naam: Ticket- {interaction.user.name}")
data['user_id'] = interaction.user.id
with open("open_channels_user_id.json", "w") as f:
json.dump(data, f)
time.sleep(3)
await interaction.channel.purge(limit=1)
else:
await interaction.channel.send("Je hebt al een ticket openstaan.")
time.sleep(5)
await interaction.channel.purge(limit=1)
async def menu(ctx):
view = Menu()
embed = discord.Embed(title="Ticket", description="Vragen, klachten of iets anders maak hier je Ticket aan en wordt zo snel mogelijk geholpen!", color=0x004BFF)
await ctx.send(embed=embed, view=view)
I don't know what to do. Pls help!
You can set the timeout value like this:
class Menu(discord.ui.View):
def __init__(self):
super().__init__(timeout=180) # Timeout value in seconds
self.value = None
If you set it to None, it will never time out, until you restart your bot.
If you want the view to persist between bot restarts, see this example here: https://github.com/Rapptz/discord.py/blob/master/examples/views/persistent.py
Related
Hi i want for my comment which will send 3 embeds and an Button when you click on the Button that you get the role "weeb"
(btw im starting bot coding im not a pro and i understand only the basics even when you can call these "basics")
btw the string text is german because it will be for a german server
The class with the Button:
import discord
from discord import ComponentInteraction
from discord.ext import commands
class RuleAcceptButton(commands.Cog):
def __init__(self, bot):
self.bot = bot
#commands.Cog.on_click(custom_id='rule-accept-btn')
async def button1(self, ctx: ComponentInteraction, _):
role_id = 1046854949373489203
def setup(bot):
bot.add_cog(RuleAcceptButton(bot))
The class with the setup command:
#commands.Cog.slash_command(base_name='setup', name='rules', description='Send a Embed of the Rules')
async def setup_rules(self, ctx):
embed_rules_1 = discord.Embed(description='sample text'
embed_rules_1.set_author(name='§1 – Allgemeine Regeln')
embed_rules_1.set_thumbnail(url='https://i.pinimg.com/originals/93/f0/00/93f0006c2d5da2f25de2951fb3f994bf.jpg')
embed_rules_2 = discord.Embed(colour=16711680, description='sample text'
# ab hier Embed2
embed_rules_2.set_author(name='§2 – Zusätzliche Regeln für Voice-Chats/Voice-Channels')
embed_rules_2.set_thumbnail(url='https://i.pinimg.com/originals/93/f0/00/93f0006c2d5da2f25de2951fb3f994bf.jpg')
# ab hier Embed3
embed_rules_3 = discord.Embed(colour=16711680, description='sample text'
embed_rules_3.set_author(name='§3 – Zusätzliche Regeln für den Chat.')
embed_rules_3.set_thumbnail(url='https://i.pinimg.com/originals/93/f0/00/93f0006c2d5da2f25de2951fb3f994bf.jpg')
await ctx.respond(embed=embed_rules_1)
await ctx.respond(embed=embed_rules_2)
await ctx.respond(embed=embed_rules_3, components=[
discord.Button(label='Accept Rules', custom_id='rule-accept-btn',style=discord.ButtonStyle.green)
i simply searched the whole internet and i didnt found anything
Here's my code (The bot answers are in Spanish)
I was trying to put the self.info['title'] in the embed description but it was an error that said 'music_cog' object has no attribute 'info':
def search_yt(self, item):
with YoutubeDL(self.YDL_OPTIONS) as ydl:
try:
self.info = ydl.extract_info("ytsearch:%s" % item, download=False)['entries'][0]
except Exception:
return False
return {
'source': self.info['formats'][0]['url'],
'title': self.info['title'],
'channel': self.info['channel']
}
#client.command()
async def p(self, ctx, *args):
embed = discord.Embed(
title = 'Reproduciendo 🎵',
description = 'song_title'
)
query = " ".join(args)
voice_channel = ctx.author.voice.channel
if voice_channel is None:
await ctx.send("Antes debes meterte a un canal de voz")
else:
song = self.search_yt(query)
if type(song) == type(True):
await ctx.send("Hubo un error al intentar reproducir la canción >-<")
else:
await ctx.send(embed=embed)
await ctx.send("**Canción agregada con exito**")
self.music_queue.append([song, voice_channel])
if self.is_playing == True:
await ctx.send('La canción se agrego a la lista de reproducción')
else:
await self.play_music()
await ctx.send("**Reproduciendo**")
Write song = self.search_yt(query) before the embed initialization and create the embed like this:
embed = discord.Embed(
title = "Reproduciendo 🎵",
description = song['title']
)
I recently discovered how to get the guild's icon URL to put it into an EMBED, but it looks horrible (far too smooth). I tried the dynamic issue from discord.js, but it did not work. Here is my code :
#PraingloBot.command(aliases=['latency', 'latence'])
async def ping(ctx):
await ctx.message.delete()
avant = time.monotonic()
calcul = await ctx.send("<:PraingloBot:901217139028017163> Calcul du ping en cours...")
lag = round((time.monotonic()-avant) * 1000)
await calcul.delete()
embedping = Embed(colour=Colour(6653959))
embedping.add_field(
name="Ping",
value=f'{round(PraingloBot.latency * 1000)} ms', inline=False
)
embedping.add_field(
name="Latence API",
value=f'{lag} ms', inline=False
)
embedping.set_author(
name='Système de ping',
icon_url=ctx.guild.icon_url
)
await ctx.send(embed=embedping)
#commands.Cog.listener()
async def on_command(self, ctx):
with open(env["JSON_DIR"] + "servers.json", "r") as f:
s = json.load(f)
if not ctx.message.content == f"{ctx.prefix}verify":
if str(ctx.guild.id) in s:
command = self.bot.get_command(ctx.message.content.split(f"{ctx.prefix}")[1])
print(command)
command.update(enabled=False)
await ctx.send(embed=discord.Embed(title="No estais verificados", description="Para poder verificar el server poner `$verify`", color=0x00fbff))
else:
command = self.bot.get_command(ctx.message.content.split(f"{ctx.prefix}")[1])
command.update(enabled=True)
I want so that if the server is not verified the command that was executed to no be executed.
I have tried with command.update() but it doesn't really seem to work
Please help...
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.