-
Notifications
You must be signed in to change notification settings - Fork 237
Channel
Channels can be either part of Guild (Server), Group Channel (Group Direct Message), User Private Channel (Direct Message).
use Discord\Parts\Channel\Channel;
A Channel can be either a text or voice channel on a Discord guild.
-
MessageRepository Only in Text Channels
$channel->messages
-
OverwriteRepository
$channel->overwrites
- ThreadRepository Incoming in v7
-
WebhookRepository
$channel->webhooks
-
VoiceMemberRepository as MemberRepository Only in Voice Channels
$channel->members
Requires GUILD
intent
Your BOT must have manage_channels
permission
You must first get the Guild object to use the code below
Create a text channel #mychannel with topic "Welcome to my channel!" with NSFW off:
$newchannel = $guild->channels->create([
'name' => 'mychannel',
// All other options are optional
'type' => Channel::TYPE_TEXT,
'topic' => 'Welcome to my channel!',
'nsfw' => false,
// more options in Docs
]);
$guild->channels->save($newchannel)->done(function (Channel $channel) {
echo 'Created a new text channel - ID: ', $channel->id;
});
https://discord.com/developers/docs/resources/guild#create-guild-channel
Change 123123123123123123
below with the Channel ID you want to retrieve
Cached, synchronous:
$channel = $discord->getChannel('123123123123123123');
You must first get the Guild object to use the code below
Cached, synchronous:
$channel = $guild->channels->get('id', '123123123123123123');
Channel can be also retrieved from related objects:
-
Message
$channel = $message->channel;
channel where the message is on -
Invite
$channel = $invite->channel;
channel where the invite is made for -
Webhook
$channel = $webhook->channel;
channel where the webhook belongs to
If the code above returns null
, you may need to fetch it first (Promise, asynchronous):
$guild->channels->fetch('123123123123123123')->done(function (Channel $channel) {
// ...
});
https://discord.com/developers/docs/resources/channel#get-channel
Your BOT must have send_messages
permission
Send "Hello world!" to the $channel
:
$channel->sendMessage('Hello world!');
https://discord.com/developers/docs/resources/channel#create-message
Your BOT must have move_members
permission
You must first get the Member object to use the code below
Move the $member
to the $channel
:
$channel->moveMember($member)->done(function () {
// ...
});
Or, change 123123123123123123
below with the Member ID:
$channel->moveMember('123123123123123123')->done(function () {
// ...
});
https://discord.com/developers/docs/resources/guild#modify-guild-member
Your BOT must have manage_roles
permission
You must first get the Member object to use the code below
Set $member
permission in the $channel
to allow send messages, attach files, but deny add reaction:
$channel->setPermissions($member, [
'send_messages',
'attach_files',
], [
'add_reactions',
])->done(function () {
// ...
});
https://discord.com/developers/docs/resources/channel#edit-channel-permissions
You can update channel properties like the name, topic, nsfw, slowmode, etc
Your BOT must have manage_channels
permission
You must first get the Guild and the Channel object to use the code below
Rename a text channel to #mycoolchannel:
$myChannel = $guild->channels->get('123123123123123123');
$myChannel->name = 'mycoolchannel';
$guild->channels->save($myChannel)->done(function (Channel $channel) {
echo 'Renamed my channel to: ', $channel->name;
});
https://discord.com/developers/docs/resources/channel#modify-channel
Your BOT must have manage_channels
permission
You must first get the Guild object to use the code below. You can either use the Channel object or the snowflake ID
$guild->channels->delete('123123123123123123')->done(function (Channel $channel) {
echo 'Deleted channel: ', $channel->name;
});
https://discord.com/developers/docs/resources/channel#deleteclose-channel
Note: This wiki is currently Work In Progress. Consider reading the docs instead.
- Application Command (Slash based)
Command Client (Message based)
- Activity
- Application
- Guild
- Private Channel
- User
Components
-
ActionRow
- Buttons
- Option (commands)
- SelectMenu
- TextInput
Builders