The goal is to make a bot that deals with postulations. He needs to create a channel for the applicant that only him (and the admins) can see, that part is ok.
He must then ask a series of questions automatically in the channel he has just created for the applicant. And that's where I'm stuck. I can't get the id of the channel automatically created.
(I'm new to programming, please be kind.)
import discord
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(prefix = "!", intents=intents)
guild = discord.Guild
@client.event
async def on_ready():
print(f'{client.user} est connecté !')
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('!startApply'):
guild = message.guild
Officier = discord.utils.get(message.guild.roles, name="Officier")
overwrites = {
guild.default_role: discord.PermissionOverwrite(read_messages=False),
guild.me: discord.PermissionOverwrite(read_messages=True),
message.author : discord.PermissionOverwrite(read_messages=True),
Officier: discord.PermissionOverwrite(read_messages=True)
}
await guild.create_text_channel(f'Apply {message.author}', overwrites=overwrites)
client.run('my_token')
I tried to put all the possible arguments, I can't send a message in the channel that the bot has just created.
CodePudding user response:
The create_text_channel()
function automatically returns the channel, which is a TextChannel
object, that the bot created.
So, to send a message in that channel, just do:
# ...
channel = await guild.create_text_channel(...)
await channel.send("...")
Hope this helps.
CodePudding user response:
Thank you very much, this is exactly the solution to my problem. Have a good day !