I had some trouble with this as well. What you need to do is:
- Go to the Discord developer pages (login if you haven’t).
- Go to the application with the bot you want to add to your channel.
- Copy the Client/Application ID.
- Go to https://discordapp.com/oauth2/authorize?client_id=CLIENT_ID_GOES_HERE&scope=bot&permissions=0 < You can set permissions for the bot here. Permissions can be calculated here.
- Select server and click authorize.
Your bot will now be a member of the server and will respond to commands you give it. Ex. !test in the code you have given.
EDIT: You can now use the permissions link (1) to generate the entire URL needed.