Discord.py Rewrite Tutorial #2 - Sending Messages & Restricting Channels_Users

**Introduction to Customizing Discord Bot Commands**

In this article, we will explore how to customize Discord bot commands using Python and the discord.py library. We will cover various aspects of command customization, including checking for valid users, roles, and channels, as well as logging and error handling.

**Setting Up a Basic Command System**

To begin, we need to set up a basic command system for our Discord bot. This involves creating a class that inherits from `discord.ext.commands.Bot` and defines the commands we want to use. In this example, we will create a simple command called "hello" that responds with a greeting message.

```python

import discord

from discord.ext import commands

# Create a new bot instance

bot = commands.Bot(command_prefix='!')

@bot.event

async def on_ready():

print(f'{bot.user} has connected to Discord!')

# Define the hello command

@bot.command(name='hello')

async def hello(ctx):

await ctx.send('Hello!')

```

In this example, we define a `Bot` instance with a prefix of "!" and create a `hello` command that responds with a simple greeting message. We then use the `@bot.event` decorator to specify an event handler for when the bot is ready.

**Checking Valid Users**

One of the key aspects of customizing Discord bot commands is checking whether the user who triggered the command is valid. In this example, we will use the `member` attribute of the `ctx` object to check if the user is a member of the server.

```python

@bot.command(name='hello')

async def hello(ctx):

await ctx.send('Hello!')

```

However, in a real-world application, we would want to handle cases where the user is not a valid member or does not have the necessary permissions. We can do this by adding additional checks using conditional statements.

```python

@bot.command(name='hello')

async def hello(ctx):

# Check if the user is a member of the server

if ctx.author in ctx.guild.members:

await ctx.send('Hello!')

else:

await ctx.send('You are not a member of this server.')

```

In this example, we use an `if` statement to check if the author of the command is a member of the server. If they are, we send a greeting message. Otherwise, we send an error message.

**Checking Roles**

Another important aspect of customizing Discord bot commands is checking whether the user has the necessary roles. We can do this using the `@commands.has_role` decorator.

```python

from discord.ext import commands

# Define a role called "moderator"

MODERATOR_ROLE = 'moderator'

@bot.command(name='hello')

@commands.has_role(MODERATOR_ROLE)

async def hello(ctx):

await ctx.send('Hello!')

```

In this example, we define a role called "moderator" and use the `@commands.has_role` decorator to specify that only users with this role can trigger the "hello" command.

**Checking Channels**

We also need to check whether the user is in the correct channel. We can do this using the `ctx.channel` attribute.

```python

@bot.command(name='hello')

async def hello(ctx):

# Check if the user is in the correct channel

if ctx.channel == ctx.guild.text_channels[0]:

await ctx.send('Hello!')

```

In this example, we use an `if` statement to check if the user is in the first text channel of the server. If they are, we send a greeting message.

**Logging and Error Handling**

Finally, we want to add some logging and error handling to our command system. We can do this using the `logging` module and the `try`/`except` block.

```python

import logging

# Create a logger

logger = logging.getLogger(__name__)

@bot.command(name='hello')

async def hello(ctx):

try:

# Check if the user is in the correct channel

if ctx.channel == ctx.guild.text_channels[0]:

await ctx.send('Hello!')

except Exception as e:

logger.error(f'Error handling command: {e}')

```

In this example, we create a logger and use a `try`/`except` block to catch any exceptions that may occur when handling the "hello" command. If an exception occurs, we log the error message using the `logger.error()` method.

**Putting it all Together**

Here's the complete code for our Discord bot:

```python

import discord

from discord.ext import commands

import logging

# Create a new bot instance

bot = commands.Bot(command_prefix='!')

# Define a logger

logger = logging.getLogger(__name__)

logging.basicConfig(level=logging.INFO)

@bot.event

async def on_ready():

print(f'{bot.user} has connected to Discord!')

@bot.command(name='hello')

async def hello(ctx):

try:

# Check if the user is in the correct channel

if ctx.channel == ctx.guild.text_channels[0]:

await ctx.send('Hello!')

except Exception as e:

logger.error(f'Error handling command: {e}')

# Define a moderator role

MODERATOR_ROLE = 'moderator'

@bot.command(name='hello')

@commands.has_role(MODERATOR_ROLE)

async def hello(ctx):

try:

# Check if the user is in the correct channel

if ctx.channel == ctx.guild.text_channels[0]:

await ctx.send('Hello!')

except Exception as e:

logger.error(f'Error handling command: {e}')

# Run the bot with the token

bot.run('YOUR_BOT_TOKEN')

```

This code sets up a basic Discord bot with two commands: "hello" and "moderator". The "hello" command responds with a greeting message, while the "moderator" command requires the user to have the moderator role. We also add logging and error handling using the `logging` module.

**Conclusion**

Customizing Discord bot commands is an essential part of building a robust and interactive bot. By following this guide, you can create custom commands that respond to user input and handle errors effectively. Remember to always test your code thoroughly and use logging and error handling to ensure that your bot behaves as expected.

"WEBVTTKind: captionsLanguage: enhey guys and welcome to the second video in my discord rewrite tutorials so today we're gonna be continuing where we left off with kind of sending messages adding some more commands we're gonna be talking about kind of getting specific things to a server like maybe how many members are on there who's online who's offline how we can check specific channels how we can check who is sending what message how we can mention members kind of going through a lot of the basic stuff but this will allow you to actually create a lot now before I continue what I want to talk about just is all this stuff is gonna be on my website so if you guys are like struggling with any of the code or you can't keep up with the pace that I'm going at just go to my website tech with tim ned go to this tutorials page you can just do that by clicking up here go to the discord bot section and then at the time of recording the side of the text-based version dumb-butt you'll be able to click on the text-based tutorial most likely right when this comes out so i'll show you for example with the first tutorial it was already out and you can kind of go through here and it explains everything that I'm doing the video just kind of like not as detailed and then they have I have all the code here that you can kind of copy as well if you run into any errors so I'm also just gonna talk about so what I do essentially when I teach these tutorials and what I learned is I just read the documentation so essentially what I did to learn rewrite is I just read through this entire documentation and then I kind of picked through the stuff that I think is important and that's not like super specific to a use case and then I teach that as like I don't know that that's just what I do right so you'll see me occasionally look over to my other screen because I just have the documentation open cuz I don't memorize this stuff I just look through and know how to use it so if you guys want to learn how to do a bunch of this stuff that I maybe don't talk about cuz look there's tons of stuff in here that you can do like I can't even begin to explain how powerful this module is just go to this link I leave it in the description and read through the documentation yourself now it's not gonna be as easy to do things as compared to watching me because I've already read through it and kind of show what's difficult and what's not but you can learn how to like maybe if you want to do sound and I don't talk about that till video 5 then you can read through this and maybe try to figure that out for yourself so essentially what we want to do in this tutorial is I already was playing around with the button here just to make sure everything's working but we want to get the server ID first now what we were doing the last video is we just I bought and it's on this server right but it could be on any server that we want and that means when we run the bot on any server it'll do the same thing now that's good in some cases but in other cases we need specific information to the server we're on for example the amount of members well that's going to be specific to the server so we need some way to access that value so to do that we actually need to get something called the server ID now to get that is well it's not challenging but it's not easy either so what I need you to do first of all let's go to your discord go to user settings not not like channel settings user settings and then you're gonna go to appearance and you're gonna scroll down to where you see developer mode now mine is already on but yours will most likely be off so you're gonna have to turn this on and even says your developer mode exposes context menu items helpful for people writing BOTS which is exactly what we're doing so we'll do that and then what we're gonna do is we're gonna go to our test server or whatever server you're working and obviously go to server settings and go to widget now if you clicked on widget before you might not have seen this page I can't promise you you did or not because I have like streamer mode enabled at some point so it's kind of weird but anyways you're gonna copy this value that's a server ID okay I don't think it's I don't think it matters if you guys know what my server ideas but anyways there you go so copy the server ID and now what we're gonna do is I'll just what do you call it exit out of this and I've already got a copied here but just copy it in so you have the server ID okay and what we're gonna do now is we're gonna type exactly this I figure out that I still have this typed rent type ID equals client don't get underscore guild and then that ID value which is you got exactly from the discord page right now we have a reference to our specific server so we can do things like count the amount of members so once you've done that what I'm gonna do now is going to add another command that's just gonna simply print out at the amount of members that are in our discord server so to do this we'll say L if message dot content equals equals and then in this case let's say users right and then this will just give us the amount of users or members in our server and obviously play with these if you want these to be something else you can make this like a - like you can do whatever command thing and you can even make it like that it doesn't to be with an exclamation point I'm just choosing to use that for my commands so now we're just going to await message dot channel dot send and then in here I'm actually going to use something called an F string so I'm gonna type F and then I'm gonna do three quotation marks and you can use this in regular Python as well but what we're gonna do now is I'm just gonna say we call it number of members and we're gonna put these little curly braces now you won't see these curly braces when you print it's just to declare that we're about to place a variable in here so that way we don't have to add like the pluses and the commas and do all that formatting for the string we can just kind of type it directly in which is really nice so we'll put these curly braces and then in here we're gonna do is gonna do ID dot member underscore count and since this is a reference to our server and by the way ID if this is giving you errors just change it to something else because it's a Python keyword but it should be fine and then we'll do member underscore count and they'll give us how many members are in our server so let's run this and see if I made any mistakes or not and now we're just gonna go I'm in the general thing here so we'll type users and you can see the number of members and it gives us the value of two because obviously we have our bought user and then Tim so sweet if we wanted we could add cool in here too cuz that is probably gonna annoy me all right so now we've got that so now how can we check what channel a users sending messages into for example in my my actual discord server so like tech with Tim here I only allow users to send like bought commands in the bought commands channel or the commands channel obviously they can still type this in other channels but if they do nothing's gonna happen so how can we do that so for example I only want to be able to send it in what one or two channels so Bach commands commands maybe mod so how can we choose those channels well first we're gonna have to actually say let me go back here to test server I need to create a new channel you're gonna call this commands okay and you can see it's a blank Channel you can add as many as you want if you want to play with multiple ones but essentially what we're gonna do is I'm gonna make a list of valid channels so I'm just gonna say it channels yeah channels equals hope that's not gonna give us any airs with anything okay channels equals and then we'll do commands now if you had another channel that you wanted to be able to send in here you do like maybe admin and you just type out the exact name and if it has a - like add the - you don't need the pound sign though you just need this okay and now what we'll do is before we send a bot reply we'll make sure that we're in a correct channel so what we could do is we can say if message dot channel because equals channels work not equals equals sorry in channels which essentially is just gonna check if it's either commands or anything else that's in this list will tab all this in and there we go so that should be working now I'm also just gonna throw a string around here I don't know if this will cause an error or not but I just want to be safe with her string and now let's just test this and see if everything's working so we're gonna discord we'll go to general and let's type hello and nothing's happening okay but that is I believe a command so now if I go here and I type below you can see that the bot responds with hi and if I do something like users it also responds with number of members to again if I try users in here it doesn't work because we're not in the correct channel so that's a really useful way to do things okay so the next thing I'm gonna do is I'm going to show you a new event and this is if a member joins so if a member joins your server likely you'd want to greet them you want to say hey welcome to the server and you want some personalized message that probably involves their name so to do this we're gonna do another client event decorator so I'll copy that and the the event this time is gonna be async so the same as before define on underscore member underscore join and this takes one parameter and I believe the parameter is member and yes awesome so member okay so what we're gonna do now is we're gonna mention this member in a message and we're gonna send it in a channel now the thing is though since this is only giving us the member of the joint is not giving us the channel they joined in we have to know what channel to uh to welcome them in so essentially 99% of you are probably gonna have all your members join through the general channel so that's probably gonna be the channel you want a message it right but for example if they were joining in the channel like I don't know like and you renamed it something else that wasn't general then you'd have to change what you're about to do here and I'll show you in one second I'm just gonna look at this okay so now what I'm gonna do is I'm just gonna make a folder I'm gonna say for channel in member dot server yes server dot channels and what this is gonna do is it's gonna get all of the channels that is in the server that the member joined okay so similar to kind of getting this guild we're just doing it in a different way and now we're gonna say if channel equals equals and then whatever the name of your what do you call it channel is and again I'll put string here I don't know if we need to do this but this is the way I did in my other code so we'll just use this for now so string channel equals equals general and this will mean we're only gonna send a message if it's in the general channel and now what we'll do is we'll say oh wait and then we'll do member server dot channels how should we do this or no I think it's like this client dot send should be something like this and then we can just say send underscore message there and then what we'll do is we'll we'll send like welcome to the server okay so I think I'm trying to understand what I did here I think this this works if channel equals general then we'll just send a message cuz we're in that channel that that should that makes sense to me but I sorry I'm having trouble to explain that so let you do another F string and then in here what we can do is well we got to add these other quotation marks I believe where's my quotation marks there we go and we'll just say welcome to the server and then in here we can say member dot mention and what this is going to do is it's gonna do that little at sign and it's going to like mention them so they get like a notification saying like welcome to the the server okay so testing this out will be interesting because I'm gonna have to either invite like another bot or something and see if that works okay you know what maybe we'll test this in another video but just just trust me on this one if it's working or you guys can you guys can tell me if it works or not and then I can tweak it in the next video alright but I'm pretty sure this should work for if a new member joins the server and I had it working on my sir I believe so you'll see that should work okay so what else could we possibly want to do okay so we figured out how we can get the channel you're sending it in but how about who's sending what like what if I only want myself to be able to use the bots well we can do that as well so we can say something like valid underscore user just equals two and then I look at a list and I'm gonna put my little tag in here nine to nine eight I think is my number and you do need this actual number sign otherwise this isn't gonna work so what I can do now is I can actually say and so we have this condition so if it's in the correct channel and the member is invalid users so to do this we'll say if the message dot author in and then again valid underscore users and one more time we'll convert this to string I don't know again if you have to do this you can play around without the string but let's see now if I get I guess we can't even test this anyways but anyways let's try this because I'm the only member in the server but let's do I don't know go to the correct channel unless type hello and see if it actually works there we go so high okay so now I want to see let's change this to a different name let's get rid of Tim and let's let's make it tea I just so it's easy to change back and now let's run this and see if it's still letting me send messages or not so now we're in the correct channel we say hello and nothing's happening it's not letting us send anything back so that was actually working correctly and this is how you can make like a list of valid users now you can also do this like based on rule like you can say if user dot role equals equals mod allow them to do this and I will go through that later but it's in the documentation where is it here if you want to look at how you can get roles and stuff it's somewhere you if you just look like roles then it should go through like all the different things on how to get that so changelog chain like you can read through that anyways okay so let's do this though so let's say you send a message and it doesn't let you are you in the wrong channel or you're not a valid user maybe you want to say something back to the user or maybe want to print something into the console so maybe we'll say like print and then we'll do another F string because these are just useful I'll say user and then whatever that username was so we'll say like message all thing tried to do command and then we'll put in here whatever that command was so message dot content so now we were doing is actually we're not gonna show anything to the user but we're gonna print to this log screen saying like this user was trying to do a command and we can just print that out so we can see what they're trying to do essentially right so let's break this let's change this so that it's actually gonna work because I am a valid user right now and we'll do this so we'll run and then we'll go here and we'll say like hello okay so now we come here and it says user Tim nine - nine eight tried to do command hello now we can also say what Chan will be tried to do it in so let's say in Channel and then again we can do message Channel and now we're have essentially like a log going within our command prompt here within our console so if I break this run this again and then do this one more time because the the channel would probably be useful so we'll do a whole load and then we'll just do another one in here and I'll say users then you can see Tim try to do command hello in channel commands Tim try to do command exclamation point users in channel general now the thing is right if I type anything it's still just gonna say that it's still gonna say what I tried to do and what think so watch this like if I just type hi it's gonna say I try to do the command hi even though it's not command and that's just because the way we have this if statement setup is we're only checking these things if they're valid user and this else statement right is only triggering if they're not avail user they're in the wrong channel so essentially that's what's gonna end up happening but I think I showed you guys enough to kind of get a grasp on how to do some stuff here to add your own commands do you send stuff back you can get the member account message content next video we're gonna do a lot more we're gonna get into like changing roles and nicknames and like all that fun stuff some more powerful things but I just wanted to give you guys kind of a beginning here again if you have any questions please join my discord tech with Tim you guys can see here if I go like - all these help channels like everyone's really helpful me go through and kind of help people with code and whatnot so I'm sure you'll be more than happy to help you I would as well follow me on Twitter and I will see you guys in the next videohey guys and welcome to the second video in my discord rewrite tutorials so today we're gonna be continuing where we left off with kind of sending messages adding some more commands we're gonna be talking about kind of getting specific things to a server like maybe how many members are on there who's online who's offline how we can check specific channels how we can check who is sending what message how we can mention members kind of going through a lot of the basic stuff but this will allow you to actually create a lot now before I continue what I want to talk about just is all this stuff is gonna be on my website so if you guys are like struggling with any of the code or you can't keep up with the pace that I'm going at just go to my website tech with tim ned go to this tutorials page you can just do that by clicking up here go to the discord bot section and then at the time of recording the side of the text-based version dumb-butt you'll be able to click on the text-based tutorial most likely right when this comes out so i'll show you for example with the first tutorial it was already out and you can kind of go through here and it explains everything that I'm doing the video just kind of like not as detailed and then they have I have all the code here that you can kind of copy as well if you run into any errors so I'm also just gonna talk about so what I do essentially when I teach these tutorials and what I learned is I just read the documentation so essentially what I did to learn rewrite is I just read through this entire documentation and then I kind of picked through the stuff that I think is important and that's not like super specific to a use case and then I teach that as like I don't know that that's just what I do right so you'll see me occasionally look over to my other screen because I just have the documentation open cuz I don't memorize this stuff I just look through and know how to use it so if you guys want to learn how to do a bunch of this stuff that I maybe don't talk about cuz look there's tons of stuff in here that you can do like I can't even begin to explain how powerful this module is just go to this link I leave it in the description and read through the documentation yourself now it's not gonna be as easy to do things as compared to watching me because I've already read through it and kind of show what's difficult and what's not but you can learn how to like maybe if you want to do sound and I don't talk about that till video 5 then you can read through this and maybe try to figure that out for yourself so essentially what we want to do in this tutorial is I already was playing around with the button here just to make sure everything's working but we want to get the server ID first now what we were doing the last video is we just I bought and it's on this server right but it could be on any server that we want and that means when we run the bot on any server it'll do the same thing now that's good in some cases but in other cases we need specific information to the server we're on for example the amount of members well that's going to be specific to the server so we need some way to access that value so to do that we actually need to get something called the server ID now to get that is well it's not challenging but it's not easy either so what I need you to do first of all let's go to your discord go to user settings not not like channel settings user settings and then you're gonna go to appearance and you're gonna scroll down to where you see developer mode now mine is already on but yours will most likely be off so you're gonna have to turn this on and even says your developer mode exposes context menu items helpful for people writing BOTS which is exactly what we're doing so we'll do that and then what we're gonna do is we're gonna go to our test server or whatever server you're working and obviously go to server settings and go to widget now if you clicked on widget before you might not have seen this page I can't promise you you did or not because I have like streamer mode enabled at some point so it's kind of weird but anyways you're gonna copy this value that's a server ID okay I don't think it's I don't think it matters if you guys know what my server ideas but anyways there you go so copy the server ID and now what we're gonna do is I'll just what do you call it exit out of this and I've already got a copied here but just copy it in so you have the server ID okay and what we're gonna do now is we're gonna type exactly this I figure out that I still have this typed rent type ID equals client don't get underscore guild and then that ID value which is you got exactly from the discord page right now we have a reference to our specific server so we can do things like count the amount of members so once you've done that what I'm gonna do now is going to add another command that's just gonna simply print out at the amount of members that are in our discord server so to do this we'll say L if message dot content equals equals and then in this case let's say users right and then this will just give us the amount of users or members in our server and obviously play with these if you want these to be something else you can make this like a - like you can do whatever command thing and you can even make it like that it doesn't to be with an exclamation point I'm just choosing to use that for my commands so now we're just going to await message dot channel dot send and then in here I'm actually going to use something called an F string so I'm gonna type F and then I'm gonna do three quotation marks and you can use this in regular Python as well but what we're gonna do now is I'm just gonna say we call it number of members and we're gonna put these little curly braces now you won't see these curly braces when you print it's just to declare that we're about to place a variable in here so that way we don't have to add like the pluses and the commas and do all that formatting for the string we can just kind of type it directly in which is really nice so we'll put these curly braces and then in here we're gonna do is gonna do ID dot member underscore count and since this is a reference to our server and by the way ID if this is giving you errors just change it to something else because it's a Python keyword but it should be fine and then we'll do member underscore count and they'll give us how many members are in our server so let's run this and see if I made any mistakes or not and now we're just gonna go I'm in the general thing here so we'll type users and you can see the number of members and it gives us the value of two because obviously we have our bought user and then Tim so sweet if we wanted we could add cool in here too cuz that is probably gonna annoy me all right so now we've got that so now how can we check what channel a users sending messages into for example in my my actual discord server so like tech with Tim here I only allow users to send like bought commands in the bought commands channel or the commands channel obviously they can still type this in other channels but if they do nothing's gonna happen so how can we do that so for example I only want to be able to send it in what one or two channels so Bach commands commands maybe mod so how can we choose those channels well first we're gonna have to actually say let me go back here to test server I need to create a new channel you're gonna call this commands okay and you can see it's a blank Channel you can add as many as you want if you want to play with multiple ones but essentially what we're gonna do is I'm gonna make a list of valid channels so I'm just gonna say it channels yeah channels equals hope that's not gonna give us any airs with anything okay channels equals and then we'll do commands now if you had another channel that you wanted to be able to send in here you do like maybe admin and you just type out the exact name and if it has a - like add the - you don't need the pound sign though you just need this okay and now what we'll do is before we send a bot reply we'll make sure that we're in a correct channel so what we could do is we can say if message dot channel because equals channels work not equals equals sorry in channels which essentially is just gonna check if it's either commands or anything else that's in this list will tab all this in and there we go so that should be working now I'm also just gonna throw a string around here I don't know if this will cause an error or not but I just want to be safe with her string and now let's just test this and see if everything's working so we're gonna discord we'll go to general and let's type hello and nothing's happening okay but that is I believe a command so now if I go here and I type below you can see that the bot responds with hi and if I do something like users it also responds with number of members to again if I try users in here it doesn't work because we're not in the correct channel so that's a really useful way to do things okay so the next thing I'm gonna do is I'm going to show you a new event and this is if a member joins so if a member joins your server likely you'd want to greet them you want to say hey welcome to the server and you want some personalized message that probably involves their name so to do this we're gonna do another client event decorator so I'll copy that and the the event this time is gonna be async so the same as before define on underscore member underscore join and this takes one parameter and I believe the parameter is member and yes awesome so member okay so what we're gonna do now is we're gonna mention this member in a message and we're gonna send it in a channel now the thing is though since this is only giving us the member of the joint is not giving us the channel they joined in we have to know what channel to uh to welcome them in so essentially 99% of you are probably gonna have all your members join through the general channel so that's probably gonna be the channel you want a message it right but for example if they were joining in the channel like I don't know like and you renamed it something else that wasn't general then you'd have to change what you're about to do here and I'll show you in one second I'm just gonna look at this okay so now what I'm gonna do is I'm just gonna make a folder I'm gonna say for channel in member dot server yes server dot channels and what this is gonna do is it's gonna get all of the channels that is in the server that the member joined okay so similar to kind of getting this guild we're just doing it in a different way and now we're gonna say if channel equals equals and then whatever the name of your what do you call it channel is and again I'll put string here I don't know if we need to do this but this is the way I did in my other code so we'll just use this for now so string channel equals equals general and this will mean we're only gonna send a message if it's in the general channel and now what we'll do is we'll say oh wait and then we'll do member server dot channels how should we do this or no I think it's like this client dot send should be something like this and then we can just say send underscore message there and then what we'll do is we'll we'll send like welcome to the server okay so I think I'm trying to understand what I did here I think this this works if channel equals general then we'll just send a message cuz we're in that channel that that should that makes sense to me but I sorry I'm having trouble to explain that so let you do another F string and then in here what we can do is well we got to add these other quotation marks I believe where's my quotation marks there we go and we'll just say welcome to the server and then in here we can say member dot mention and what this is going to do is it's gonna do that little at sign and it's going to like mention them so they get like a notification saying like welcome to the the server okay so testing this out will be interesting because I'm gonna have to either invite like another bot or something and see if that works okay you know what maybe we'll test this in another video but just just trust me on this one if it's working or you guys can you guys can tell me if it works or not and then I can tweak it in the next video alright but I'm pretty sure this should work for if a new member joins the server and I had it working on my sir I believe so you'll see that should work okay so what else could we possibly want to do okay so we figured out how we can get the channel you're sending it in but how about who's sending what like what if I only want myself to be able to use the bots well we can do that as well so we can say something like valid underscore user just equals two and then I look at a list and I'm gonna put my little tag in here nine to nine eight I think is my number and you do need this actual number sign otherwise this isn't gonna work so what I can do now is I can actually say and so we have this condition so if it's in the correct channel and the member is invalid users so to do this we'll say if the message dot author in and then again valid underscore users and one more time we'll convert this to string I don't know again if you have to do this you can play around without the string but let's see now if I get I guess we can't even test this anyways but anyways let's try this because I'm the only member in the server but let's do I don't know go to the correct channel unless type hello and see if it actually works there we go so high okay so now I want to see let's change this to a different name let's get rid of Tim and let's let's make it tea I just so it's easy to change back and now let's run this and see if it's still letting me send messages or not so now we're in the correct channel we say hello and nothing's happening it's not letting us send anything back so that was actually working correctly and this is how you can make like a list of valid users now you can also do this like based on rule like you can say if user dot role equals equals mod allow them to do this and I will go through that later but it's in the documentation where is it here if you want to look at how you can get roles and stuff it's somewhere you if you just look like roles then it should go through like all the different things on how to get that so changelog chain like you can read through that anyways okay so let's do this though so let's say you send a message and it doesn't let you are you in the wrong channel or you're not a valid user maybe you want to say something back to the user or maybe want to print something into the console so maybe we'll say like print and then we'll do another F string because these are just useful I'll say user and then whatever that username was so we'll say like message all thing tried to do command and then we'll put in here whatever that command was so message dot content so now we were doing is actually we're not gonna show anything to the user but we're gonna print to this log screen saying like this user was trying to do a command and we can just print that out so we can see what they're trying to do essentially right so let's break this let's change this so that it's actually gonna work because I am a valid user right now and we'll do this so we'll run and then we'll go here and we'll say like hello okay so now we come here and it says user Tim nine - nine eight tried to do command hello now we can also say what Chan will be tried to do it in so let's say in Channel and then again we can do message Channel and now we're have essentially like a log going within our command prompt here within our console so if I break this run this again and then do this one more time because the the channel would probably be useful so we'll do a whole load and then we'll just do another one in here and I'll say users then you can see Tim try to do command hello in channel commands Tim try to do command exclamation point users in channel general now the thing is right if I type anything it's still just gonna say that it's still gonna say what I tried to do and what think so watch this like if I just type hi it's gonna say I try to do the command hi even though it's not command and that's just because the way we have this if statement setup is we're only checking these things if they're valid user and this else statement right is only triggering if they're not avail user they're in the wrong channel so essentially that's what's gonna end up happening but I think I showed you guys enough to kind of get a grasp on how to do some stuff here to add your own commands do you send stuff back you can get the member account message content next video we're gonna do a lot more we're gonna get into like changing roles and nicknames and like all that fun stuff some more powerful things but I just wanted to give you guys kind of a beginning here again if you have any questions please join my discord tech with Tim you guys can see here if I go like - all these help channels like everyone's really helpful me go through and kind of help people with code and whatnot so I'm sure you'll be more than happy to help you I would as well follow me on Twitter and I will see you guys in the next video\n"