問題描述
我應該放什麼行,這樣當我寫東西時,Discord 機器人會以我想要的方式響應(discord.py)? (What lines should I put so that when I write something the Discord bot responds in a way that I want (discord.py)?)
我不知道我應該寫什麼行來讓機器人回复我沒有前綴的消息,就像我說“你好”,他說“你好!”......你能幫幫我嗎?
這是我的代碼
import discord
import os
import requests
import json
import random
from web import keep_alive
from discord.ext import commands
def command_prefix(bot, message):
if message.guild is None:
return ''
else:
return '\\'
client=commands.Bot(command_prefix=command_prefix,case_insensitive=True)
client.remove_command('help')
@client.event
async def on_ready():
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching,name='Having fun in 4 SERVER ‑ DM Tomm#7615 to get the my invite link'))
print('We have logged in as {0.user}'.format(client))
async def on_message(self, message):
if message.content.startswith('here come dat boi'):
await self.send_message(message.channel, 'o shit waddup!')
client.run('TOKEN')
感謝所有答案。
祝你有個美好的一天!
湯姆
強>參考解法
方法 1:
Can't you just change this:
async def on_message(self, message):
if message.content.startswith('here come dat boi'):
await self.send_message(message.channel, 'o shit waddup!')
To this:
async def on_message(self, message):
if message.content == 'Hi':
await self.send_message(message.channel, 'Hello!')
方法 2:
Which version is this?... For rewrite its this:
@client.event
async def on_message(message):
if message.content.startswith('here come dat boi'):
return await message.channel.send('o shit waddup!')
elif message.content.startswith('Hi'):
return await message.channel.send('Hello')
(by user15948497、Ludal、Juuzou Suzuya)