I want to send this embed in direct. How can i send this embed in ditect?
#bot.commnd()
#commands.has_role(1012777316864241694)
async def loader(ctx):
emb = discord.Embed(title = '', colour=0x87CEEB)
emb.set_author(name=bot.user.name)
emb.set_thumbnail(url='')
emb.add_field(name="", value = '', inline = False)
emb.add_field(name="", value = '', inline = False)
emb.add_field(name="", value = '', inline = False)
emb.add_field(name="", value = '', inline = False)
emb.set_image(url ="")
await bot.send_message(embed=emb)
await ctx.message.delete()
await asyncio.sleep(5)
You can send a direct message to a use by using Member.send
To send to the command user, you can use:
await ctx.author.send(embed=emb)
All attributes of messages including embeds work no differently when sending to users.
Related
This is the code:
class ticket_launcher(discord.ui.View):
def __init__(self) -> None:
super().__init__(timeout=None)
#discord.ui.Button(label='Create a ticket', style = discord.ButtonStyle.blurple, custom_id = 'ticket_button')
async def ticket(self, button: discord.ui.Button, interaction: discord.Interaction):
ticket = discord.utils.get(interaction.guild.text_channels, name = f'ticket-for-{interaction.user.name}-{interaction.user.discriminator}')
if ticket is not None: await interaction.response.send_message(f'You already have a ticket open at {ticket.mention}!', ephemeral = True)
else:
overwrites = {
interaction.guild.default_role: discord.PermissionOverwrite(view_channel = False),
interaction.user: discord.PermissionOverwrite(view_channel = True, send_messages = True, attach_files = True, embed_links = True),
interaction.guild.me: discord.PermissionOverwrite(view_channel = True, send_messages = True, read_message_history = True)
}
channel = await interaction.guild.create_text_channel(name=f'ticket-for-{interaction.user.name}-{interaction.user.discriminator}', overwrites=overwrites, reason=f'Ticket for {interaction.user}.')
await channel.send(f'{interaction.user.mention} created a ticket!')
await interaction.response.send_message(f'I have opened a ticket for you at {channel.mention}.', ephemeral=True)
tree = app_commands.CommandTree(client=client)
#tree.command(guild = discord.Object(id=TICKET_CHANNEL), name='ticket', description='Launches the ticket system.')
async def ticket(interaction: discord.Interaction):
embed = discord.Embed(title='If you have any problems click the big blue button below!', color=discord.Colour.blue())
await interaction.channel.send(embed=embed, view=ticket_launcher())
await interaction.response.send_message('Ticketing system has been launched successfully.', ephemeral=True)
it gives me this error message in the output:
Traceback (most recent call last):
File "c:\Users\schul\Desktop\MORE PYTHON\bot.py", line 214, in <module>
class ticket_launcher(discord.ui.View):
File "c:\Users\schul\Desktop\MORE PYTHON\bot.py", line 219, in ticket_launcher
async def ticket(self, button: discord.ui.Button, interaction: discord.Interaction):
TypeError: 'Button' object is not callable
So can anyone mind helping me out with this, as this kinda annoying, would be thankfull if you would've helped me out :)
In your button decorator, use button in lowercase:
#discord.ui.button(label='Create a ticket', style = discord.ButtonStyle.blurple, custom_id = 'ticket_button')
Docs: https://discordpy.readthedocs.io/en/latest/interactions/api.html?highlight=button#discord.ui.button
#bot.command()
async def serverinvite(ctx,guild_id : discord.guild.Guild.id):
if ctx.author.id == 761156852276789248:
server = bot.get_guild(id=guild_id)
invite = await server.abc.GuildChannel.create_invite()
e = discord.Embed(title="invite",colour=0x9E003A,description=invite)
e.set_thumbnail(url=ctx.guild.icon_url)
e.set_author(name=bot.user.name, icon_url='https://cdn.discordapp.com/attachments/967363930492108821/967499783692517466/sdsasa.gif?size=4096')
await ctx.send(embed=e)
else:
pass
what wrong i want it send me invite to server
with id:
ID = int
guild = client.get_guild(ID)
guildchannel = guild.text_channels[0] # get the first channel of the guild
invitelink = await guildchannel.create_invite(max_uses=1) # create the invite link
with server name:
servername = "str"
guild = discord.utils.get(client.guilds, name=f'{servername}')
guildchannel = guild.text_channels[0] # get the first channel of the guild
invitelink = await guildchannel.create_invite(max_uses=1) # create the invite link
I trying to pull Avro files from an API link while using Asyncio. Currently it just returns nothing if the link is to an avro file - while all my other API calls which pull json data work. What am I missing?
credentials = {'authorization': XXXXX}
async def get_data(link, session,creds)-> None:
async with session.get(url, url=link, headers=credential) as res:
content = await res.read()
r = await session.request('GET', url=str(link), headers=creds)
data = await r
return
async def data_distributor_function(credential)-> None:
async with aiohttp.ClientSession() as session:
link_list = ["https://.....","https://.....","https://.....","https://.....","https://....."]
tasks = []
for link in link_list:
tasks.append(wait_for(get_data( link=link, session=session,creds=credential),timeout=10))
results = await asyncio.gather(*tasks, return_exceptions=True)
return
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
data = asyncio.run(data_distributor_function(credential),debug=True)
If I don't do the API call in asyncio, I can just use a standard request and it works (it's just slow).
reply = requests.request("GET", link, credentials)
Hi I want to use the command for only 2 users with their user id can you help me pls there is my code :
python
#bot.command()
async def sub(ctx, vintedurl):
x = await ctx.channel.create_webhook(name="Discord-test")
with open("config.json", 'w+') as configedit:
configs["suburl"][str(x.url)] = {}
configs["suburl"][str(x.url)]["url"] = str(vintedurl)
configs["suburl"][str(x.url)]["salon"] = str(ctx.channel.name)
json.dump(configs,configedit,indent=4)
await ctx.send("Webhook ajouté avec le lien !")
You can either check in your command directly, like this:
#bot.command()
async def sub(ctx, vintedurl):
if ctx.author.id not in (123, 456): # your desired IDs here
return
x = await ctx.channel.create_webhook(name="Discord-test")
with open("config.json", 'w+') as configedit:
configs["suburl"][str(x.url)] = {}
configs["suburl"][str(x.url)]["url"] = str(vintedurl)
configs["suburl"][str(x.url)]["salon"] = str(ctx.channel.name)
json.dump(configs,configedit,indent=4)
await ctx.send("Webhook ajouté avec le lien !")
Or you could also create your custom check:
from discord.ext import commands
def custom_check(ctx):
return ctx.author.id in (123, 456) # your desired IDs here
#bot.command()
#commands.check(custom_check)
async def sub(ctx, vintedurl):
x = await ctx.channel.create_webhook(name="Discord-test")
with open("config.json", 'w+') as configedit:
configs["suburl"][str(x.url)] = {}
configs["suburl"][str(x.url)]["url"] = str(vintedurl)
configs["suburl"][str(x.url)]["salon"] = str(ctx.channel.name)
json.dump(configs,configedit,indent=4)
await ctx.send("Webhook ajouté avec le lien !")
Docs for custom checks: https://discordpy.readthedocs.io/en/master/ext/commands/api.html?highlight=check#discord.ext.commands.check
You can use simple if else to check the ctx.author.id :)
#bot.command()
async def onlytwopplcanuseme(ctx):
user_ids = [1234567890123456, 1234567890123456] # Replace the two user IDs here
if ctx.author.id in user_ids:
await ctx.reply("Approved!")
else:
await ctx.reply("Not approved!")
I've been trying to figure this out forever now, but it seems that my discord.py command prefix for my bot does not work. Currently, here is my code:
players = {}
client = commands.Bot(command_prefix = "!")
#client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')
await client.change_presence(activity=discord.Game(name="with your words!"))
called_once_an_hour.start()
#client.command()
async def test():
await client.send('test')
#client.command(pass_context = True)
async def join(ctx):
channel = ctx.message.author.voice.voice_channel
await client.join_voice_channel(channel)
#client.command(pass_context = True)
async def leave(ctx):
server = ctx.message.server
voice_client = client.voice_client_in(server)
await voice_client.disconnect()
#client.command(pass_context = True)
async def play(ctx):
server = ctx.message.server
voice_client = client.voice_client_in(server)
player = await voice_client.create_ytdl_player('https://www.youtube.com/watch?v=YMw-9mXfccY')
players[server.id] = player
player.start()
print(f"Playing Are you winning son in server voice client: {voice_client}")
First client command was mainly for debugging purposes, but its just never called out.
I also think I already have all the necessary imports
Your test command needs to look like:
async def test(ctx):
await ctx.send('test')
I can run this successfully with !test
The context is passed by default, pass_context = True is no longer necessary.
See the commands docs: https://discordpy.readthedocs.io/en/latest/ext/commands/commands.html