'Trying to send a message to a recently created Text Channel using discord.py
The code in question below works flawlesly, it creates a channel and gives it a description. But i can't figure out how to proceed from here and have it send a message to this channel right after creation, any help would be appreciated.
# Text Channel
settings = utils.get_serv_settings(guild)
if 'text_channels' in settings and settings['text_channels'] and is_gold(guild):
try:
r = await guild.create_role(name="🎤🤖vc {}".format(c.id))
except discord.errors.Forbidden:
return c
await creator.add_roles(r)
overwrites = {
guild.default_role: discord.PermissionOverwrite(read_messages=False),
guild.me: discord.PermissionOverwrite(read_messages=True),
r: discord.PermissionOverwrite(read_messages=True),
}
if 'stct' in settings:
showto_r = guild.get_role(settings['stct'])
if showto_r:
overwrites[showto_r] = discord.PermissionOverwrite(read_messages=True)
tc = await guild.create_text_channel(
utils.nice_cname(settings['text_channel_name']) if 'text_channel_name' in settings else "voice context",
category=primary.category,
overwrites=overwrites,
topic=("<a:arrowg:972810849783808040> Type '!vc help | This channel is only visible to members of your voice channel, "
"It will be deleted when everyone leaves. VC ID: {}".format(c.id)))
settings = utils.get_serv_settings(guild)
settings['auto_channels'][primary.id]['secondaries'][c.id]['tc'] = tc.id
settings['auto_channels'][primary.id]['secondaries'][c.id]['tcr'] = r.id
utils.set_serv_settings(guild, settings)
if creator in c.members:
unlock_channel_request(c)
else:
log("{} Still trying to move {}".format(str(c.id)[-4:], creator.display_name), guild)
lock_channel_request(c, 20)
lock_user_request(creator, 20)
return c
Solution 1:[1]
To send a message to the channel your just created.
channel = await guild.create_text_channel(*args) # this returns the channel that was created so u can use it to send the message
await channel.send("message")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |