简体   繁体   中英

How do you make a discord bot respond without commands (but in python)?

I want to make a bot in discord that, when you send it a string of some sort, or an event happens, it'll send a message to a discord channel. However, when I tried adding an "input" function (the simplest there is), it couldn't work at all. What other ways are there to input strings into programs like this?

You can use webhooks to do this.

First, you should install the discord_webhook module by running pip install discord_webhook into the terminal. Now, you can write your program. This is a very simple example:

from discord_webhook import DiscordWebhook

url = # Put webhook url here...
webhook = DiscordWebhook(url=f'{url}', content=input('Enter a message: '))
response = webhook.execute()

You should replace the url variable with your webhook link. In case you don't know how to get a webhook link, this is an example on how to do it:

例子

If you don't know anything about discord bots, freeCodeCamp did an amazing video on it. Look that up. They are amazing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM