Discord.py Error Message Whenever User Dms Bot
Using the code linked here, I had created a custom prefix for my bot a couple months ago. However, I ran into an issue when I was finally getting into DM responses. Due to the cust
Solution 1:
Something I would recommend you to do is to make a default prefix in bot DMs. Let's say you want the default prefix to be .
, change your get_prefix
function to:
def get_prefix(client, message):
try:
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
return prefixes[str(message.guild.id)]
except KeyError: # if the guild's prefix cannot be found in 'prefixes.json'
with open('prefixes.json', 'r') as k:
prefixes = json.load(k)
prefixes[str(message.guild.id)] = 'bl!'
with open('prefixes.json', 'w') as j:
json.dump(prefixes, j, indent = 4)
with open('prefixes.json', 'r') as t:
prefixes = json.load(t)
return prefixes[str(message.guild.id)]
except: # I added this when I started getting dm error messages
return '.' # This will return "." as a prefix. You can change it to any default prefix.
Post a Comment for "Discord.py Error Message Whenever User Dms Bot"