[英]How do I set bot mention as a bot prefix? (discord.py)
我將我的機器人設置為能夠擁有自定義前綴,現在我希望我的機器人能夠在有人提到它時做出響應。 當有人@bot
或@bot help
時,它應該響應。
def get_prefix(client, message):
with open('prefixes.json', 'r') as f: ##we open and read the prefixes.json, assuming it's in the same file
prefixes = json.load(f) #load the json as prefixes
return prefixes[str(message.guild.id)] #recieve the prefix for the guild id given
client = commands.Bot(
command_prefix= (get_prefix),
intents = intents
)
好的,根據@Bruce21,我得到了你想問的問題,這是一個很長的方法,它沒有像@bot help
那樣響應。 我有一個簡單的方法。
嘗試: client = commands.Bot(command_prefix= when_mentioned_or(get_prefix), intents = intents)
我知道了。
def get_prefix(client, message):
with open('prefixes.json', 'r') as f: ##we open and read the prefixes.json, assuming it's in the same file
prefixes = json.load(f) #load the json as prefixes
prefix = prefixes[str(message.guild.id)]
return when_mentioned_or(*prefix)(client, message) #recieve the prefix for the guild id given
client = commands.Bot(
command_prefix= (get_prefix),
intents = intents
)
@client.event
async def on_message(message):
mention = f'<@!{client.user.id}>'
if message.content == mention:
with open('prefixes.json', 'r') as f: ##we open and read the prefixes.json, assuming it's in the same file
prefixes = json.load(f) #load the json as prefixes
prefix = prefixes[str(message.guild.id)]
await message.channel.send(f"You called? My prefix for this server is `{prefix}`. Admins can change it by using `{prefix}changeprefix <new prefix>`")
await client.process_commands(message)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.