I do command, that if people click on emoji, create ticket.
#bot.command()
async def ticket(ctx):
embed = discord.Embed(
color = discord.Color.green()
)
embed.set_author(name="Откыть запрос")
embed.add_field(name="To create a ticket react with 📩", value="help")
await ctx.send( embed = embed )
emoji = '📩'
await ctx.channel.purge(limit=1)
message = await ctx.send(embed=embed)
await message.add_reaction(emoji=emoji)
This is message, where people can click on emoji.
And this is code to create channel:
if str(payload.emoji) == "📩":
guild = bot.get_guild(payload.guild_id)
channel = await guild.create_text_channel('Ticket')
guild = message.guild
If someone can, help please to do that the person who created it and the 3 highest roles would have access to the ticket. And aso that the channel name is from 0000 in order to infinity, or only the name of the one who created the ticket
I know, that few people will help, but I hope
guild = bot.get_guild(payload.guild_id)
overwrites = {
guild.me: discord.PermissionOverwrite(view_channel=True),
payload.member: discord.PermissionOverwrite(view_channel=True),
guild.default_role: discord.PermissionOverwrite(view_channel=False)
}
for role in guild.roles[1:4]:
overwrites[role] = discord.PermissionOverwrite(view_channel=True)
channel = await guild.create_text_channel(f"Ticket-{payload.member.display_name}", overwrites=overwrites)
Related
I am new to coding so sorry if this is easy to do. But what I am wanting to have my bot do is send a message to my private guild when it is added or removed from another guild. Also if it could say the name of said guild that would help as well.
#client.event
async def on_guild_join(guild):
chn = client.get_channel(YOUR_PRIVATE_GUILD_CHANNEL_ID)
embed = discord.Embed(title=f"Bot Invited",description=f"""
**User Name:** {bot_entry[0].user.name}
**User ID:** {bot_entry[0].user.id}
**Server Name:** {guild.name}
**Server ID:** {guild.id}
**Members Count:** {len(guild.members)}
""", colour=0x2dc6f9)
embed.set_footer(icon_url=guild.icon_url, text=guild.name)
embed.set_author(name=f"{bot_entry[0].user.name}#{bot_entry[0].user.discriminator}", icon_url=bot_entry[0].user.avatar_url)
embed.timestamp = datetime.datetime.utcnow()
server_invite = await guild.text_channels[0].create_invite(max_age = 0, max_uses = 0)
await chn.send(f"{server_invite}", embed=embed)
Something like this?
#client.event
async def on_guild_join(guild):
await client.get_channel(idchannel).send(f"{client.name} has joined")
When I ban someone with my bot, all recent message get deleted, so I was wonder if is there a way to keep messages.
#bot.command()
#commands.has_permissions(administrator=True)
async def ban(ctx, user: discord.User, *, reason = None):
ban = await ctx.reply(embed = discord.Embed(description = f'{loading_emoji} Banning {user.mention} from `server1` and `server2`...', color = 0x00BF23), mention_author=True)
s1 = await bot.fetch_guild(server1)
s2 = await bot.fetch_guild(server2)
await s1.ban(user, reason = reason)
await s2.ban(user, reason = reason)
await asyncio.sleep(0.9)
await ban.edit(embed = discord.Embed(title = 'Success!', description = f'{shield_emoji} Banned {user.mention} from `server1` and `server2`!', timestamp = datetime.utcnow(), color = 0x00BF23), mention_author=True)
Edit: So i checked and i just needed to add delete_message_days=0 in await s1.ban(user, reason = reason) so should look like this await s1.ban(user, reason = reason, delete_message_days=0) thx for the help
You can use the delete_message_days (int) Parameter in Guild.ban
Api Docs
I am using code that I found here.
But, I'm getting an error that the client object doesn't have the attribute send_message. I have tried message.channel.send but that failed as well.
#client.event
async def on_ready():
Channel = client.get_channel('YOUR_CHANNEL_ID')
Text= "YOUR_MESSAGE_HERE"
Moji = await client.send_message(Channel, Text)
await client.add_reaction(Moji, emoji='🏃')
#client.event
async def on_reaction_add(reaction, user):
Channel = client.get_channel('YOUR_CHANNEL_ID')
if reaction.message.channel.id != Channel:
return
if reaction.emoji == "🏃":
Role = discord.utils.get(user.server.roles, name="YOUR_ROLE_NAME_HERE")
await client.add_roles(user, Role)
One of the reasons why your code might not be working is because you may have your channel id stored in a string. Your code shows:
Channel = client.get_channel('YOUR CHANNEL ID')
The code above shows that your channel id is stored in a string, which it should not be. With the code above, your actual code may look like this:
Channel = client.get_channel('1234567890')
Instead you should have:
Channel = client.get_channel(1234567890)
I'm new to discord bot making, and I'd like to have the bot add a reaction to my message that, once pressed, allows the user reacting to pick up a role. What would be the code to allow me to do this? Thank you.
This is a very well written and formatted question! In order for the bot to detect that the reaction is on a specific message, you can do many ways. The easiest way would be to be by ID, so I'm just going to do this with a simple command.
messageIDs = []
#client.event
async def on_raw_reaction_add(payload):
global messageIDs
for messageID in messageIDs:
if messageID == payload.message_id:
user = payload.member
role = "roleName"
await user.add_roles(discord.utils.get(user.guild.roles, name = role))
#client.command()
async def addMessage(ctx, messageID):
global messageIDs
emoji = "👍"
channel = ctx.message.channel
try:
msg = await channel.fetch_message(messageID)
except:
await ctx.send("Invalid Message ID!")
return
await msg.add_reaction(emoji)
messageIDs.append(messageID)
Currently, I have a logs on my bot, It works fine but the problem is that it takes logs from all servers that the bot it in. So, how do I make it server specific?
#commands.Cog.listener()
async def on_message_delete(self, message):
embed = Embed(
description=f"Message deleted in {message.channel.mention}", color=0x4040EC
).set_author(name=message.author, url=Embed.Empty, icon_url=message.author.avatar_url)
embed.add_field(name="Message", value=message.content)
embed.timestamp = message.created_at
channel=self.bot.get_channel(channel_id)
await channel.send(embed=embed)
This is my code for message deleting
Compare message's guild id with yours
Below is the revised code:
#commands.Cog.listener()
async def on_message_delete(self, message):
if message.guild.id == YOUR_GUILD_ID:
embed = Embed(
description=f"Message deleted in {message.channel.mention}", color=0x4040EC
).set_author(name=message.author, url=Embed.Empty, icon_url=message.author.avatar_url)
embed.add_field(name="Message", value=message.content)
embed.timestamp = message.created_at
channel = self.bot.get_channel(channel_id)
await channel.send(embed=embed)